Python-101 Flashcards
(22 cards)
What is the syntax for squaring?
a**2
How do you define vars?
Just use the var name and value, no keyword required
What are keywords used in for loop?
for, in and : (colon sign)
Write code to iterate the Strings?
for i in “Str1”, “Str2”, “Str3”:
print(“Hello”+i)
Do we have line terminators in pyhton?
Nope
What does range function do?
It helps is looping till the argument given
for i in range(10):
print(i)
How can you look for help
Just type help(arg), in are you can pass any keyword or function, press q to exit
Can we use parenthesis to specify the scope of the code(e.g for loop)?
No, Use tabs
How does the _ use in for loop?
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 to comment?
Start with #
What is diff b/w single , double and triple quote
No Diff between singl and double quote, but yes triple double quotes(“”””) specifes multiple lines
What is negative indexes used for?
It specifies the item in reverse, -1 refers to last item , -2 second last and so on
How do you do String slicng with index based?
Use : sign such as
print(str[1:4]);,
How can you slice from 1 to second last>
print(str[0:-2])
In PY are the String immutable?
Yes
What is meaning of * in String context?
It says that if you want to repeat the string many times
How can I find the presssence of a char in a String?
Use equals operator or use in, like
‘á’ in MyString this will print true
IS it required to use if keyword
Nope, statement itself will do that
What does len do?
len(obj) shows the length of the object
What does enumerate do?
enumerate() does the iteration of any object whichhas index
How Do you add escape character?
prepend with \
How should I nullify the effect of escape char and let it get printed?
Use r or R like
r”the \xHH is Hexadecimal char”