Data Types and Variables Flashcards

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?

A

hello world

25
Q

‘Hello world’.split(‘ ‘)

[‘Hello’, ‘world’]

-What does this do?

A

Splits string into an array with 2 values

26
Q

Split whitespace

  • ‘Hello \t\n there,\t\t\t stranger.’.split() OUTPUT?
  • What happened?
A

[‘Hello’, ‘there,’, ‘stranger.’]

-Each word got split into a list

27
Q

Replace parts of a string

replace(old, new, # of times)

‘Hello world’.replace(‘H’, ‘h’)

OUTPUT and expain

A

H was replaced with h

hello world

28
Q

Reversing a string

mystring = ‘Hello world’

mystring[::-1]

A

‘dlrow olleH’

29
Q

Python string format with f-strings

Ex :

my_age = 40

f ‘ ‘ (What goes in the single quotes?)

OUTPUT: My age is 32

A

f’My age is {my_age - 8}’

  • f string allows you to scan for expressions in curly braces {ag }
30
Q

functions

A

something you can call, such as an argument

31
Q

print() funciton

-You can mix

A

print text to our screen.

-argument types

32
Q

bool(binary)

A
33
Q

method

A

Ex: title()

An action python can perform on a piece of data

34
Q

first_name = “ada”

last_name = “lovelace”

fullname =

f string that prints ‘ada lovelace’

A

fullname =f “{first_name} {last_name} “

print(fullname)

35
Q

n newline and tab for hello world (3 lines)

A

print(“New plan:\n\t1.Look at dolphins\n2.Smile\n3.Die”)

36
Q

Stripping Whitespace

(right)

rstrip()

-Ex: Use this for lol =”python “ to take away the whitespace

(left)

A

lol = “python”

lol = lol.rstrip()

lol = lol.strip()

37
Q

Exponents

How would 5^2 and 6^3 be written>?

A

5 **2

6**3

38
Q

floats(decimals)

0.2 * 2.0

A

.4

39
Q

Intergers and Floats

Defaults to float when mixed with an interger

4/2

8 + 3.0

A
  1. 0 decimal
  2. 0
40
Q

Underscores in numbers

universenumber= 14_000

A

14000

41
Q

Multiple assignment

-Assign x,y and z variable to 0 in the same line

A

x,y,z= 0,0,0

42
Q

Constants

(varaible that stays the same throughout the program)

A

MAX_CON = 100

43
Q
A
44
Q
A
45
Q
A
46
Q
A
47
Q
A