Python 3 Flashcards

1
Q

Range based for loop with i
10 numbers
Goes up by 2 each loop

A

For i in range(0,10,2)

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

Python comments

A

#

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

X = 10
Convert to float

A

Y = Float(×)

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

X = 10
Convert to string

A

Y = str(×)

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

Boolean <=

A

Less than or equals to

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

Boolean >=

A

Greater than or equal to

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

Difference between = And ==

A

= is assignment operator
== is equal comparison operator

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

!= is

A

Not equal operator

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

If statement for x and y being equal

A

If( x == y):
Print(“ok”)
Else:
Print no

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

While loop for continuing until x = n

A

While (× != ‘n’ ):

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

Stop a loop if x == 5

A

If ×==5:
Break

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

Skip iteration if x = 9

A

If x==9:
Continue

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

To get a random # between 0 and 100

A

Import random

X = random.randit(0,100)

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

Exit a program if you is typed

A

Import sys

If response == “you” :
Sys.exit()

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

X = 5.543357
Round to 3 decimal places

A

X = round(x,3)

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

Functon for a+b

A

Def adder(num1,num2):
X = num1+num2
Return x

My Number = adder(1,3)

17
Q

Python shebang

A

Windiws
#! Python 3
Linux
#! /usr/bin/python3

18
Q

Windows batch file ( to run command file)

A

@py (address) helloWorlds2.py %*

@pause (for pause)

19
Q

Regular expressions are good for?
Use what library?

A

For pattern matching
Import re

20
Q

In re.compile (r’\d\d\d-\d\d\d\d’)
The r does?

A

Tells the compiler these are for pattern matching not escape characters

21
Q

Create a class called robot

A

Class Robot :

22
Q

A function in a class is called a ____ and has what added

A

A method
Has argument self added
Ex
Def weight (self) :
Print(blah)

23
Q

What is a constructor?
How is it written

A

It initializes values
(2 underscores before and after)
Def __init__ (self, height,weight,color):
self.height = height
Ect