Python-101 Flashcards

1
Q

What is the syntax for squaring?

A

a**2

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

How do you define vars?

A

Just use the var name and value, no keyword required

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

What are keywords used in for loop?

A

for, in and : (colon sign)

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

Write code to iterate the Strings?

A

for i in “Str1”, “Str2”, “Str3”:

print(“Hello”+i)

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

Do we have line terminators in pyhton?

A

Nope

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

What does range function do?

A

It helps is looping till the argument given
for i in range(10):
print(i)

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

How can you look for help

A

Just type help(arg), in are you can pass any keyword or function, press q to exit

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

Can we use parenthesis to specify the scope of the code(e.g for loop)?

A

No, Use tabs

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

How does the _ use in for loop?

A

When you do not want to use a var , and just let the loop do work many times
for i in range(10):
print(“Hello”)

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

How to comment?

A

Start with #

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

What is diff b/w single , double and triple quote

A

No Diff between singl and double quote, but yes triple double quotes(“”””) specifes multiple lines

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

What is negative indexes used for?

A

It specifies the item in reverse, -1 refers to last item , -2 second last and so on

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

How do you do String slicng with index based?

A

Use : sign such as

print(str[1:4]);,

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

How can you slice from 1 to second last>

A

print(str[0:-2])

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

In PY are the String immutable?

A

Yes

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

What is meaning of * in String context?

A

It says that if you want to repeat the string many times

17
Q

How can I find the presssence of a char in a String?

A

Use equals operator or use in, like

‘á’ in MyString this will print true

18
Q

IS it required to use if keyword

A

Nope, statement itself will do that

19
Q

What does len do?

A

len(obj) shows the length of the object

20
Q

What does enumerate do?

A

enumerate() does the iteration of any object whichhas index

21
Q

How Do you add escape character?

A

prepend with \

22
Q

How should I nullify the effect of escape char and let it get printed?

A

Use r or R like

r”the \xHH is Hexadecimal char”