Python Flashcards

1
Q

download file from web from command line

A

import urllib
urllib.urlretrieve (“http://www.example.com/songs/mp3.mp3”, “mp3.mp3”)
import urllib
urllib.urlretrieve (“http://www.example.com/songs/mp3.mp3”, “mp3.mp3”)

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

move and rename a file in os

A

import os

os.rename(‘somefile’, ‘somewhere/else’)

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

return a new sorted list in ascending order

A

sorted([5, 2, 3, 1, 4])

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

Use list.sort() method of a list to modify list in place.

A

> > > a = [5, 2, 3, 1, 4]
a.sort()
a
[1, 2, 3, 4, 5]

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

Add item to the end of a list

A

list.append(x)

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

Return the number of times x appears in a list.

A

list.count(x)

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

Argument specifier for any object with a string representation.

A

%s

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

Argument specifier for integers

A

%d

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

Argument specifier for floating point numbers

A

%f

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

Floating point numbers with a fixed amount of digits to the right of the .

A

%.f

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

Argument specifier for Integers in hex representation (lowercase/uppercase)

A

%x/%X

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

print the number of a’s in a string called string

A

print string.count(‘a’)

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

print a slice of the string string

A

print string[3:7]

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

print the length of a string called string

A

print len(string)

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

print the location of the first occurrence of the letter b in a string called string

A

pring string.index(‘b’)

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

make letters in var astring uppercase

A

astring.upper( )

17
Q

make letters in a string called astring lowercase

A

astring.lower( )

18
Q

argument in a function

A

The piece of code you put between the function’s parenthesis when you call it

19
Q

parameter in function

A

Name you put between the function’s parenthesis when you define it.

20
Q

Function import aka Pulling in just a single function from a module

A

from module import function (where module and function are the names of the module and the function)

21
Q

Import everything in a module without having to call that module every time you want to use it in the future.

A

from module import *

22
Q

explicit string conversion

A

str( )

23
Q

Syntax for a string formatter (to print strings without explicitly typing the variable

A

print “%s” % (variable)

24
Q

Order of operations in boolean

A

Not, and, or