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 :: how to hide turtle in python 
Python :: plt.imshow not showing image 
Python :: python creating a dict from a string 
Python :: how to close windows in selenium python without quitting the browser 
Python :: find largest 10 number in dataframe 
Python :: Python cheat sheet pdf download 
Python :: all letters an numbers py array 
Python :: ordered dictionary python 
Python :: ImportError: No module named colored 
Python :: roots of quadratic equation in python 
Python :: import word_tokenize 
Python :: python count number of unique elements in a list 
Python :: remove index from dataframe pandas 
Python :: Python Program to count the number of lowercase letters and uppercase letters in a string. 
Python :: pathlib path python 
Python :: import pil pycharm 
Python :: Get game status discord.py 
Python :: df = df.reset_index(level=0) 
Python :: pandas create new column conditional on other columns 
Python :: how to determine python project parent dir 
Python :: how to read excel file in python 
Python :: python recursive sum of digit 
Python :: tqdm python 
Python :: create exe from python script 
Python :: django m2m .add 
Python :: intersection between two arrays using numpy 
Python :: select random value from list python 
Python :: pandas dataframe crosstab 
Python :: python fillna with mode 
Python :: run powershell script in python 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =