Python Flashcards
Learn all about the python programming language (47 cards)
Where is the python interpreter usually installed?
The Python interpreter is usually installed as /usr/local/bin/python3.4 file path.
How do you set the python interpreter path to C:\python3.4
set path=%path%;C:\python3.4
When inside the python terminal, how do you quit?
quit()
How do you start a comment in python?
#
What are the symbols of add, subtract, multiply, divide and remainder in python?
+, -, *, /, and %
Just as in BODMAS, python respects parenthesis.
which will be treated first: (50 - 5*6) / 4 ?
The Multiplication in the bracket, followed by the subtraction and the total will be divided by 4
5 ** 2 ?
25
> > > width = 20
height = 5 * 2
width * height
200
How do you escape single quotes in ‘doesn’t’ ? to give “doesn’t”
‘doesn't’
s = ‘First line.\nSecond line.’ without print(), produces what?
‘First line.\nSecond line.’
s = ‘First line.\nSecond line.’ with print(s), produces what?
First line.
Second line.
What does r in print(r’C:\some\name’) does?
If you don’t want characters prefaced by \ to be interpreted as special characters, you can use raw strings by adding an r before the first quote
output: C:\some\name
String Literals allow multi-line comments, how do you write them?
”””\
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
“””
3 * ‘un’ + ‘ium’ produces?
‘unununium’
# 3 times ‘un’, followed by ‘ium’
‘Py’ ‘thon’ returns what?
‘Python’ because of the string literal. A variable and a string literal would not work
A variable text with a string literal in parenthesis:
text = (‘Put several strings within parentheses ‘
‘to have them joined together.’), returns what?
‘Put several strings within parentheses to have them joined together.’
word = ‘Python’
word[0] # character in position 0
Returns what?
‘P’
word = ‘Python’
word[5] # character in position 5
Returns what?
‘n’
word = ‘Python’
word[-1] # last character
Returns what?
‘n’
word = ‘Python’
word[-2] # second-last character
Returns what?
‘o’
word = ‘Python’
word[-6]
Returns what?
‘P’
word = ‘Python’
word[0:2] # characters from position 0 (included) to 2 (excluded)
Returns what?
‘Py’
word = ‘Python’
word[2:5] # characters from position 2 (included) to 5 (excluded)
Returns what?
‘tho’
s[:i] + s[i:] = s
word = ‘Python’
word[:2] + word[2:]
Returns what?
‘Python’