Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python for else

list = [99, 98, 97, 96, 95, 94]

for number in list:
  if number == 2:
    print("There is a 2 in the list")
  	break
else:
  print("There are no 2's in the list")
  
# The else statement is only reached if the for loop
# has run all the way through without breaking
Comment

python for/else

for n in range(2, 10):
    for x in range(2, n):
        if n % x == 0:
            print( n, 'equals', x, '*', n/x)
            break
    else:
        # loop fell through without finding a factor
        print(n, 'is a prime number')
Comment

PREVIOUS NEXT
Code Example
Python :: double char python 
Python :: sorting a list of dictionaries 
Python :: Exit code: ENOENT. spawn /usr/bin/python ENOENT 
Python :: count consecutive values in python 
Python :: Use module Crypto.Cipher.PKCS1_OAEP instead 
Python :: python sort dict by value 
Python :: python find file name 
Python :: how to make a checksum to a file python 
Python :: numpy random matrix 
Python :: how to find the speed of a python program 
Python :: python datetime compare date 
Python :: shell script to run python 
Python :: add value to dictionary python 
Python :: pip uninstalled itself 
Python :: if name == main 
Python :: django authenticate 
Python :: pandas excel sheet name 
Python :: import ndimage 
Python :: run python file from another python file 
Python :: group by 2 unique attributes pandas 
Python :: numpy divide except 
Python :: select pandas by t dtype python 
Python :: map example in python 
Python :: this figure includes axes that are not compatible with tight_layout, so results might be incorrect 
Python :: not equal to in django filter 
Python :: sqlalchemy_database_uri 
Python :: python autocorrelation plot 
Python :: how to install python pyautogui 
Python :: Range python iterate by 2 
Python :: python file to array 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =