Python Flashcards
Conditional List — All
score=325 wickets=7 catch=4 list_cond=[score>320, wickets<8, catch>3]
if(all(list_cond)):
print(“Pranjal Saxena”)
else:
print(“Lose”)
Condition Inside the print Function
print(“odd” if int(input(“Enter a num: “))%2 else “even”)
Conditional List — Any
score=200 wickets=7 catch=4 list_cond=[score>320, wickets<8, catch>3]
if(any(list_cond)):
print(“Win”)
else:
print(“Lose”)
Multiple Inputs in One Go
5 8 9
a,b,c=input(“Enter three inputs “).split()
Swap Like a Pro
salary=85000
exp=3
salary,exp=exp,salary
Take Out the Duplicate Data
li=[1,5,8,6,5,9,6,9,5,6,9,6,5,4]
print(list(set(li)))
Most Repeated Object in a list
li=[1,5,8,6,5,9,6,9,5,6,9,6,5,4,”a”,”a”,”b”,”b”,”a”,”a”,”a”]
print(max(set(li), key=li.count))
Magic of List Comprehension
li=[i**3 for i in range(1,15) if i%2==0]
print(li)
.format()
print(“My name is {} and my number is {}”.format(‘AL’, ‘682’))
print(“My name is {x} and my number is {xx}”.format(x=’AL’, xx=’682’))
sets
{1,1,2,2,3}
{1, 2, 3}
help
shift tab
list comprehension
[x**2 for x in range(5)]