Python Flashcards

1
Q

Types of variables and how to print them.

A

int
float
str
bool

print(“Age is: {}”.format(age))
print(f”Age is: {age}”)
print(“Age is: “, age)

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

How to accept data from console?

A

age = input(“What is your age?”)

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

Type conversion.

A
age = input("What is your age?")
future_age = int(age) + 5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

String variables have which functions?

A
capitalize()
count()
index()
isalpha()
isdecimal()
islower()
join()
lower()
lstrip()
replace()
rindex()
rstrip()
title()
upper()
zfill()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Arithmatic operators
Comparison operators
Logical operators

A

+ - * / % // **

> < >+ <= == !=

and or not

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

Operator precedence

A

** Exponentiation (raise to the power)
~ + - Complement, unary plus and minus (method names for the last two are +@ and -@)
* / % // Multiply, divide, modulo and floor division
+ - Addition and subtraction
» « Right and left bitwise shift
& Bitwise ‘AND’td>
^ | Bitwise exclusive OR' and regular OR’
<= < > >= Comparison operators
<> == != Equality operators
= %= /= //= -= += *= **= Assignment operators
is is not Identity operators
in not in Membership operators
not or and Logical operators

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

Condition

A
if age < 25:
    print("Young")
elif age < 40:
    print("Very energetic")
else:
    print("New young")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

While loop

For loop

A

while count < 5:
print(count)
count += 1

for item in range(5):
print(“Item is {}”.format(item))

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

Lists

A

my_list = [“1”, “5”, “7”, “12”]

.append()
.clear()
.copy()
.count()
.extend()
.index()
.insert()
.pop()
.remove()
.reverse()
.sort()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Tuple

A

my_tuple = (1, 2, 3, 4)

Tuples are immutable

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

Interpreted or Compiled?

A

Python is interpreted language.

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

Print multiple *

A

print(‘*’ * 10)

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

Function in Python?

How are arguments passed?

A
def my_function(name):
    print("Hello {}".format(name))

my_function(“chini”) # Calling the function

Positional Arguments - based on order.
Keyword Arguments - based on keywords in arguments.

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

Sort a list.

A

my_list = [‘1’, ‘2’, ‘3’]
my_list.sort() #prints ascending order
my_list.sort(reverse=True) #prints descending order
my_list.sort(key=myFunc) #uses custom function to sort.

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

Dictionaries

A

As of Python 3.7, dictionaries are ordered.

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