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 integers
no
what must you put when using \t and \n
quotations because they’re strings
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:
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
== - comparison
how do you find input for diff data types
str(input(“ “))
int(input(“ “))
float(input(“ “))
1)can integer be stored in float, why
2)can float be stored in integer, why
1)yes, integer requires less memory than float
2)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 (can’t do mathematical operations on them)
1)can integer and float be stored in string
2)can a string be an integer/ float
1)yes
2)no
how do you use if conditional statement
if ( ):
, start here
-indentation
how do you use elif conditional statement
elif ( ):
, start here
-indentation
how do you use else conditional statement
else:
, start here
-indentation
how do you use nested ifs
if ( ):
if ( ):
-indentation
how do you use and & or conditions in conditional statements
eg. if ( age> 10 and age< 20):
eg. if ( age> 10 or age< 20):
how do you use conditional statement to get something in between value
eg. if (0 < username <10):
nota: % - remainder, // - integer, / - float (for division)
note: all chars are strings, not all strings are chars
Iteration
looping