Python Flashcards

1
Q

Conditional List — All

A
score=325
wickets=7
catch=4
list_cond=[score>320,
           wickets<8,
           catch>3]

if(all(list_cond)):
print(“Pranjal Saxena”)
else:
print(“Lose”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Condition Inside the print Function

A

print(“odd” if int(input(“Enter a num: “))%2 else “even”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Conditional List — Any

A
score=200
wickets=7
catch=4
list_cond=[score>320,
           wickets<8,
           catch>3]

if(any(list_cond)):
print(“Win”)
else:
print(“Lose”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Multiple Inputs in One Go

5 8 9

A

a,b,c=input(“Enter three inputs “).split()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Swap Like a Pro

A

salary=85000
exp=3
salary,exp=exp,salary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Take Out the Duplicate Data

A

li=[1,5,8,6,5,9,6,9,5,6,9,6,5,4]

print(list(set(li)))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Most Repeated Object in a list

A

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))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Magic of List Comprehension

A

li=[i**3 for i in range(1,15) if i%2==0]

print(li)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

.format()

A

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’))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

sets

{1,1,2,2,3}

A

{1, 2, 3}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

help

A

shift tab

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

list comprehension

A

[x**2 for x in range(5)]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly