Python-101 Flashcards
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