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
+ used with strings
Concatenates the strings in the print function
25
, used with print
``` Removes the line feed at the end of print, I.e., print "Mary", print "lamb" Results in: Mary lamb ```
26
\
(Backslash) - escape character
27
print """...""" | print '''...'''
Triple quotes allow printing of lines as typed
28
raw_input( )
Prompts user for a string or a value, outputs a string
29
int(raw_input( ))
Converts string to a number
30
Input( )
Converts entry as if it is python code; security issues, don't use
31
raw_input("string")
Prompts for input by printing "string"
32
pydoc
Terminal command that prints python documentation, I.e., pydoc raw_input() prints doc for raw_input()
33
From sys import argv
Imports function argv from sys (sys is a package)
34
argv
Packs arguments given to a program; first one is the function (script) name
35
module
Another name for a function or feature
36
Prompt
"> " is one, I.e., raw_input("> ")
37
var = raw_input("> ")
Passes user input to var
38
var = open(filename)
Opens the file "filename" and passes file object to var
39
var.read()
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
close()
``` closes the file, e.g.: var = open(filename) ... .... var.close() ```
41
.close()
Close the file
42
.read()
Read the file
43
.readline()
Read one line of a text file
44
.truncate()
Empty the file
45
.write(stuff)
Writes stuff to the file
46
Open(filename, 'w')
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
from os.path import exists
Imports exists module
48
exists(filename)
Returns True if filename exists, else False | This is the exists module
49
cat
Concatenation, Linux command | cat filename prints the contents of filename
50
len(string)
Outputs the character count of a string as a number
51
def
``` defines a function def print_two(*args): arg1, arg2 = args print "arg1: %r, arg2: %r" % (arg1, arg2) ```
52
.seek(0)
Rewinds a .read() of a file
53
+= n
Increments a variable by n | var += 2 is equivalent to var = var + 2
54
return
``` Returns a value from a function def add(a, b) return a + b Executing var = add(3, 4) places 7 in var ```