basics Flashcards

(33 cards)

1
Q

int

A

Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.

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

float

A

Float, or “floating point number” is a number, positive or negative, containing one or more decimals.

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

complex

A

Complex numbers are written with a “j” as the imaginary part.

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

string

A

String literals in python are surrounded by either single quotation marks, or double quotation marks.

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

Cast as string

A

str()

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

Cast as int

A

int()

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

Cast as float

A

float()

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

Cast as complex

A

complex()

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

Addition

A

+

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

Subtraction

A

-

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

Multiplication

A

*

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

Division

A

/

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

Modulus

A

%

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

Exponentiation

A

**

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

Floor division

A

//

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

and

A

Returns True if both statements are true

x < 5 and x < 10

17
Q

or

A

Returns True if one of the statements is true

x < 5 or x < 4

18
Q

not

A

Reverse the result, returns False if the result is true

not(x < 5 and x < 10)

19
Q

is

A

Returns true if both variables are the same object

x is y

20
Q

is not

A

Returns true if both variables are not the same object

x is not y

21
Q

List

A

is a collection which is ordered and changeable. Allows duplicate members.
A list is a collection which is ordered and changeable. In Python lists are written with square brackets.
thislist = [“apple”, “banana”, “cherry”]

22
Q

Tuple

A

is a collection which is ordered and unchangeable. Allows duplicate members.
A tuple is a collection which is ordered and unchangeable. In Python tuples are written with round brackets.
thistuple = (“apple”, “banana”, “cherry”)

23
Q

Set

A

is a collection which is unordered and unindexed. No duplicate members.
A set is a collection which is unordered and unindexed. In Python sets are written with curly brackets.
thisset = {“apple”, “banana”, “cherry”}

24
Q

Dictionary

A

is a collection which is unordered, changeable and indexed. No duplicate members.
A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.
thisdict = {
“brand”: “Ford”,
“model”: “Mustang”,
“year”: 1964
}

25
elif
``` The elif keyword is pythons way of saying "if the previous conditions were not true, then try this condition". a = 33 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") ```
26
if
If you have only one statement to execute, you can put it on the same line as the if statement. if a > b: print("a is greater than b")
27
while
``` With the while loop we can execute a set of statements as long as a condition is true. i = 1 while i < 6: print(i) i += 1 ```
28
break
``` With the break statement we can stop the loop even if the while condition is true: i = 1 while i < 6: print(i) if i == 3: break i += 1 ```
29
continue
``` With the continue statement we can stop the current iteration, and continue with the next: i = 0 while i < 6: i += 1 if i == 3: continue print(i) ```
30
for loop
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). fruits = ["apple", "banana", "cherry"] for x in fruits: print(x)
31
in
The in keyword has two purposes: The in keyword is used to check if a value is present in a sequence (list, range, string etc.). if "banana" in fruits: print("yes") The in keyword is also used to iterate through a sequence in a for loop: for x in fruits: print(x)
32
def
``` a function is defined using the def keyword def my_function(): print("Hello from a function") ```
33
lambda
Is used to create an anonymous function, can be used to create a function within a function lambda arguments : expression x = lambda a, b, c : a + b + c print(x(5, 6, 2))