Exercise 22 - Python Words & Symbols Flashcards

0
Q

print ‘string’

A

Prints a string

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

print “string”

A

Prints a string

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

#

A

(Octothorpe) - starts a comment

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

+

A

(Plus) - adds

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

-

A

(Minus) - subtracts

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

/

A

(Slash) - divides

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

*

A

(Asterisk) - multiplies

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

%

A

(Percent sign) - mod or modulus function

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

<

A

Less than - compares two values or strings, returns True or False

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

>

A

Greater than - compares two values or strings, returns True or False

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

<=

A

Less than equal - compares two values or strings, returns True or False

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

> =

A

Greater than equal - compares two values or strings, returns True or False

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

=

A

Assigns a value or string to a variable, I.e., var = “ text” or var = 3

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

,

A

Comma, separates lists of things

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

%s

A

Format character, string

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

%d

A

Format character, number

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

%r

A

Format character, returns input, I.e., raw contents of the variable = ‘representation’

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

% var

A

Places var in formatter location

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

% (var1, var2, var3)

A

Places vars in multiple formatter locations

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

3.0, for example

A

Appending .0 to the 3 results in floating point math operations

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

round()

A

Rounds a floating point number

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

False

A

Logical false

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

True

A

Logical true

23
Q
  • used with a string
A

Repeats a string char, I.e., print “.” * 10 results in ……….

24
Q

+ used with strings

A

Concatenates the strings in the print function

25
Q

, used with print

A
Removes the line feed at the end of print, I.e., 
print "Mary", 
print "lamb"
Results in:
Mary lamb
26
Q

\

A

(Backslash) - escape character

27
Q

print “"”…”””

print ‘'’…’’’

A

Triple quotes allow printing of lines as typed

28
Q

raw_input( )

A

Prompts user for a string or a value, outputs a string

29
Q

int(raw_input( ))

A

Converts string to a number

30
Q

Input( )

A

Converts entry as if it is python code; security issues, don’t use

31
Q

raw_input(“string”)

A

Prompts for input by printing “string”

32
Q

pydoc

A

Terminal command that prints python documentation, I.e., pydoc raw_input() prints doc for raw_input()

33
Q

From sys import argv

A

Imports function argv from sys (sys is a package)

34
Q

argv

A

Packs arguments given to a program; first one is the function (script) name

35
Q

module

A

Another name for a function or feature

36
Q

Prompt

A

”> “ is one, I.e., raw_input(“> “)

37
Q

var = raw_input(“> “)

A

Passes user input to var

38
Q

var = open(filename)

A

Opens the file “filename” and passes file object to var

39
Q

var.read()

A

Reads the contents of var if var is file info, e.g.:
var = open(filename)
print var.read()
Prints contents of filename as contained in var

40
Q

close()

A
closes the file, e.g.:
    var = open(filename)
    ...
    ....
    var.close()
41
Q

.close()

A

Close the file

42
Q

.read()

A

Read the file

43
Q

.readline()

A

Read one line of a text file

44
Q

.truncate()

A

Empty the file

45
Q

.write(stuff)

A

Writes stuff to the file

46
Q

Open(filename, ‘w’)

A

Opens filename and allows writing to the file. Can use:
‘w’ write, ‘r’ read, ‘a’ append
Default is read, so ‘r’ can be omitted

47
Q

from os.path import exists

A

Imports exists module

48
Q

exists(filename)

A

Returns True if filename exists, else False

This is the exists module

49
Q

cat

A

Concatenation, Linux command

cat filename prints the contents of filename

50
Q

len(string)

A

Outputs the character count of a string as a number

51
Q

def

A
defines a function
def print_two(*args):
      arg1, arg2 = args
      print "arg1: %r, arg2: %r" % (arg1, arg2)
52
Q

.seek(0)

A

Rewinds a .read() of a file

53
Q

+= n

A

Increments a variable by n

var += 2 is equivalent to var = var + 2

54
Q

return

A
Returns a value from a function
def add(a, b)
      return a + b
Executing var = add(3, 4) places 7 in var