4. Numbers, Boolean, None, Value and more. Flashcards
Data type in Python
integer - int
floating-point numbers - float
string - str
boolean - bool
Result of a floating-point division (/) is always _________
float
Result of other operations…
float - if either num is float
int - if otherwise
True and False first letter must be
CAPATILISED
How to write an operation for square root?
**(decimal/fraction)
How ‘and’ works
Returns True if both left
and right are true
How ‘or’ works
Returns True if either the
left or the right is true.
How ‘not’ works
Returns True if the value
being tested is False
None Value represent
- Represent null values or nothingness.
* Not the same as False, or an empty string, or 0
To write comment, we need to add ____ infront
#
Type of comment
Block Comments = indented at the same level as the code block
Inline Comments = placed on the same line as a statement
a = a + b →
a += b
a = a * b →
a *= b
a = a // b →
a //= b
a = a % b →
a %= b
Type of value obtained from input() is always
str
True for int and float
!= 0
False for str
”” #no space!
Type of Python output format
String format()
F-String
How String format () looks
y = x.format(*args, **kwargs) ex:
y = “{0} is {1} years old”.format(“Lady Gaga”, 33)
or
name = “Lady Gaga” age = 33 y = “{0} is {1} years old”.format(name, age)
How String format () looks
> > > name = ‘Tony’
age = 40
f’{name} is {age} y.o.’
Syntax Error
Grammatical error.
Runtime Error
Errors discovered while program is running.
Logic Error
• Occurs when a program does not perform as intended.
• Python interpreter will not show any error message, but will
produce wrong result.