Python commands Flashcards

1
Q

Embed a variable in a string

A

f”some string {somevar}”

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

format an existing string

A

existing_string= “some string {}”. existing_string.format(variable OR “string”)

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

tell print to not end the line with a newline character and go to the next line.

A

print(var1 + var2, end = “ “)

print(var3 + var4)

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

print a string repeatedly 10 times (no loop)

A

print(“string” * 10)

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

print something on a new line

A

“string\nstring”

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

print “as many rows as you like”

A

print(“"”enter string
for as many rows as you like
“””)

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

Escape sequence: Backslash ()

A

\

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

Escape sequence: single quote

A

'

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

Escape sequence: double quote

A

"

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

Escape sequence: ASCII bell (BEL)

A

\a

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

Escape sequence: ASCII backspace (BS)

A

\b

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

Escape sequence: ASCII formfeed (FF) (format)

‘insert a page break’

A

\f

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

Escape sequence: ASCII linefeed (LF) (new line)

A

\n

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

Escape sequence: Character named name in the Unicode database (Unicode only)

A

\N{name}

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

Escape sequence: Carriage return (CR) (resets to left-most in a row and overwrites with the rest of the line)

A

\r

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

Escape sequence: horizontal tab

A

\t

17
Q

Escape sequence: Character with 16-bit hex value xxxx

A

\uxxxx

18
Q

Escape sequence: Character with 32-bit hex value xxxxxxxx

A

\Uxxxxxxxx

19
Q

Escape sequence: ASCII vertical tab (VT) - pushes text down a line but still ‘in line’ with string.

A

\v

20
Q

Escape sequence: character with octal value ooo

A

\ooo

21
Q

Escape sequence: character with hex value hh

A

\xhh

22
Q

record user input as string variable

A

var = input(“e.g. enter name here: “)

23
Q

record user input at integer

A

var = int(input())

24
Q

argument variable that holds command line arguments entered into the Python code

A

from sys import argv
var1, var2, var3 = argv

when running code with CLI, type Python 3.6 scriptname.py var2name var3name