Python General Code Syntax Flashcards

1
Q

x = raw_input()

A

reads text from standard input and stores the entry into a variable

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

x = raw_input(‘Enter Value’)

A

prompts user with text in parentheses

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

argv

A

argument variable

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

var, var1, var2, var3, . . . = argv

A

unpacks the command line parameter into their respective variables. The first is always the program name (.py file). And the following parameter are loaded into their respective variables

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

import

A

imports a module into a python program

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

txt = open(filename)

A

opens a file and returns a file object which is stored in the variable txt.

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

txt.read()

A

Reads the text stored in the file object referenced by the variable txt.

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

print “some text”

A

prints text to standard out using double quotes

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

print ‘some text’

A

prints text to standard out using single quotes

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

print “print it’s text”

A

prints text to standard out including a single quote

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

python program_name.py

A

Executes a python program from the terminal

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

some text

A

An “octothorpe” also known as ‘pound’, ‘hash’, or ‘mesh’ or whatever name makes you chill out!

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

print “ some text %s” % variable_name

A

Format character for string, replaces the %s with the value stored in ‘variable_name’

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

print “some text %s and %s some more text” % (var_1, var_2)

A

Format characters for multiple variable, replaces the %s in the order found in the parenthesis.

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

%r

A

Format character, which returns a result which is valid python syntax using the repr( ) function.

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

print var_x

A

prints the content of var_x to standard output

17
Q

hilarious = False
joke_eval=”Isn’t that joke funny?! %r”
print joke_eval % hilarious

A

print out the string ‘joke_eval’ with the repr(hilarious) replacing the %r in the ‘joke_eval’ string

18
Q

print “ print this %s” % ‘Stuff’

A

prints the string in quotes replacing the format character with the text in the single quotes

19
Q

print “.” * 10

A

print 10 dots in a row to standard output

20
Q

List

A

A list is a container of things that are organized in order. A list starts with a left bracket, list of items separated by a comma, and end with a right bracket.

21
Q

list.append(x)

A

adds an item x to the end of the list

22
Q

list.extend(L)

A

Extends a list by appending all the items of a given list L

23
Q

list.insert(i, x)

A

Inserts x into list at index i.

24
Q

list.remove(x)

A

removes the first item in the list with value x

25
Q

list.pop( [i] )

A

removes from list the item at index i, if no index is give the last item in the list is removed.

26
Q

list.index(x)

A

returns the first index in the list with value x

27
Q

list.count(x)

A

returns the number of times x appears in list

28
Q

list.sort()

A

sort the items in list, in place

29
Q

list.reverse()

A

reverse the items in list, in place

30
Q

if - statement

A

if boolean expression :

indent statements

31
Q

if - else statement

A

if boolean expression :
indent statements
else:
indent statements

32
Q

if - elif - else statement

A
if boolean expression:
    indent statements
elif boolean expression:
    indent statements
else:
    indent statements
33
Q

for-loop w/ list

A

for number in numbers:

print number

34
Q

for-loop w/ range

A

for i in range(0, 6):

print i

35
Q

while-loop statement

A

while boolean expression:

indent statements