Data Types and Variables Flashcards

(47 cards)

1
Q

(text) string

A

“double quotes” and ‘single quotes’

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

implicit type casting

A

instead of string f= “fff”

you can do f = “fff” amd the result is the same

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

Comments

A

like this

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

Addition operator + for

a= “lol”

b=”no”

A

a + b

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

string concatonation of strings “andy” and “rom”

(combine)

A

print(“andy” + “rom”)

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

\n newline for “hello world” (print 3 lines)

A

print(“Hello World\nHello World\nHello World”)

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

Can operators have different variable types?

(Ex: a=5 , b=”lol” -> print(a + b)

A

No, the variable types must match

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

Alternating string quotes

Ex:String concatonation is done with the “+” sign.

How is this written?

A

(‘String Concatenation is done with the “+” sign.’)

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

input() function

input(“What is your name”)

A

Lets the user enter in a string

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

comments

single line

multiline

A

hey whats up

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

len function

Ex:

len(“fax”)

  • string bn = “jams”

len(bn)

A
  • # prints (the length of the string)

3

-#prints(length of the string)

4

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

Variable

A

labels for storing information(values)

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

Operator precedence

A

PEMDAS

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

Declaring a variable

Ex: Named result with a value of 3

A

result = 3

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

Expression

-Are these expressions?

3 * 3 , result + 4

A

anything that Python can evaluate to a value

-Yes!

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

Data type

-Is string and bool a data type?

A

classes and variables that are usually predefined

-Yes!

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

What does type() function do?

-Ex:

lmao = 5

type(lmao)

Output: ?

A

Shows the class or variable type of the variable

-

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

Variable/data type rules

  • What can they include?
  • What MUST they start with?
A
  • Lowercase and uppercase letters,numbers and underscores: _
  • letter or the underscore character and be case-sensitive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Camel Case

  • What is it for real cool person?
  • Python naming convention for real cool person ?
A

Common variable naming convention

  • realCoolperson
  • Underscore real_cool_person
20
Q

Escaping(for strings)

-Give an example in this(single quote):

It’s an escaped quote

-Give an example in this(double quotes):

I’m a so-called “scipt kiddie”

A

-Add a \ BEFORE the ‘ or “ to prevent confusion

‘It's an escaped quote!’

-“I’m a so-called "script kiddie"”

21
Q

Multiline strings

-Ex:

This is line 1,

… this is line 2,

… this is line 3.

A
  • Triple quotes

”"”This is line 1,

… this is line 2,

… this is line 3.”””

22
Q

Multiline strings with quotes inside

-Ex: He said: “Hello, I’ve got a question” from the audience

A

-He said: “Hello, I’ve got a question” from the audience

23
Q

‘a’ + ‘b’ OUTPUT?

‘a’ - ‘b’ OUTPUT?

A
  • a+b
  • Minus with string doesn’t work
24
Q

mystring = “Hello World”

mystring.lower()

OUTPUT?

25
'Hello world'.split(' ') ['Hello', 'world'] -What does this do?
Splits string into an array with 2 values
26
Split whitespace - 'Hello \t\n there,\t\t\t stranger.'.split() OUTPUT? - What happened?
['Hello', 'there,', 'stranger.'] -Each word got split into a list
27
Replace parts of a string replace(old, new, # of times) 'Hello world'.replace('H', 'h') OUTPUT and expain
hello world #H was replaced with h
28
Reversing a string ## Footnote mystring = 'Hello world' mystring[::-1]
'dlrow olleH'
29
Python string format with f-strings Ex : my\_age = 40 f ' ' (What goes in the single quotes?) OUTPUT: My age is 32
f'My age is {my\_age - 8}' - f string allows you to scan for expressions in curly braces {ag }
30
functions
something you can call, such as an argument
31
print() funciton -You can mix
print text to our screen. -argument types
32
bool(binary)
33
method
Ex: title() An action python can perform on a piece of data
34
first\_name = "ada" last\_name = "lovelace" fullname = f string that prints 'ada lovelace'
fullname =f "{first\_name} {last\_name} " print(fullname)
35
n newline and tab for hello world (3 lines)
print("New plan:\n\t1.Look at dolphins\n2.Smile\n3.Die")
36
Stripping Whitespace (right) rstrip() -Ex: Use this for lol ="python " to take away the whitespace (left)
lol = "python" lol = lol.rstrip() lol = lol.strip()
37
Exponents How would 5^2 and 6^3 be written\>?
5 \*\*2 6\*\*3
38
floats(decimals) 0.2 \* 2.0
.4
39
Intergers and Floats Defaults to float when mixed with an interger 4/2 8 + 3.0
2. 0 decimal 11. 0
40
Underscores in numbers universenumber= 14\_000
14000
41
Multiple assignment -Assign x,y and z variable to 0 in the same line
x,y,z= 0,0,0
42
Constants (varaible that stays the same throughout the program)
MAX\_CON = 100
43
44
45
46
47