Chap 8 - programing python - print, if/elif/else, (nested) loops, len, string manipulation, arrays Flashcards
name 6 data types
-integer
-string
-boolean
-float
-character (char)
-date
how do you use the print function
print(“ “)
2 ways you can print messages on print function
-comma
-concatenation (adding)
meaning of concatenation
join together
how do you use comma when printing
use comma between words
how do you use concatenation when printing
use ( + ) to add the strings
what is the difference between using comma and concatenation
space in comma, no space in concatenation
can you add strings
yes
can you add strings and integers
no
what data types are \t and \n
strings
what must you put when using \t and \n
quotations
what does \t do
a tab of space
what does \n do
a new line
what does = do
assignment of variable
what does != mean
not equal
3 rules for variables
-has to start with a char
-case sensitive
-no special char and spaces - willc hange program (except underscore)
arithmetic operation for
-addition
-subtraction
-multiply
-divide
remainder
-power
-squared
- +
- -
- *
- / (float), // (integer)
- %
- **
- **(1/2)
relational operation for:
-greater than
-greater than or equal
-smaller than
-smaller than or equal
-equal (Equality (eg, 2 obj, same 2 content))
-not equal (Equality (eg, 2 obj, same 2 content))
- >
- > =
- <
- <=
- ==
- !=
logical operators
- and
- or
- not
eg. if not hungry:
bitwise operators for:
-bitwise AND
-bitwise OR
-bitwise NOT
-bitwise XOR
-bitwise left shift
-bitwise right shift
- &
- |
- ~
- «
- > >
operation for identity true
is
-Identity (eg, 2 obj, 1 content) - refer back to same memory
operation for identity false
is not
-Identity (eg, 2 obj, 1 content) - refer back to same memory
operation for membership true
in
-Membership - check if value exists in a sequence
operation for membership false
not in
-Membership - check if value exists in a sequence
which takes place first: maths operations or assignment of variable
maths operations
note: explain each thing when explaining assignment
eg. c = a=b
- c: variable
- +: addition of a and b
- =: assignment of variable
equality vs identity vs memebership
equality - checks if obj has same contents (2 obj, same 2 content)
identity - check if obj are the same by refer back to same memory (2 obj, 1 content)
membership - check if value exists in a sequence
what does = do
assignment of variables
how do you find input for string
str(input(“ “))
how do you find input for integer
int(input(“ “))
how do you find input for float
float(input(“ “))
can integer be stored in float, why
-yes
-integer requires less memory than float
can float be stored in integer, why
-no
-float requires more memory than integer
what is the drawback of integer and float stored as string
they’ll be used as a string - lose their properties kinda
can integer and float be stored in string
yes
can a string be an integer
no
can a string be a float
-yes
-using float( )
how do you use if conditional statement
if ( ):
, start here
how do you use elif conditional statement
elif ( ):
, start here
how do you use else conditional statement
else:
, start here
how do you use nested ifs’
if ( ):
if ( ):