Revision w6-w15 Flashcards
assignment operator
=
To define a variable you must ..?
The name of the variable
The initial value of the variable
Any words that are reserved for special
purposes in a computer language
Reserved words
Name Python’s data types:
int, float, string, complex numbers and Boolean
True or False?
The data type is associated with the value, not the variable
True
Is Python a dynamically or statically typed language?
Python is a dynamically typed language, in other words, the
variables data type can change during runtime
num=1
str=’s’
num2=2
satuation1: num + s
satuation2: num + num2
what is the output?
1: error
2: 3
Can a constant value change?
Yes
Is Python a interpreted or compiled language?
Python is an interpreted language —it does not use a compiler.
What is the difference between ‘/’, ‘//’ and ‘%’?
/ --> prints float //--> (Floor division) discards the fractional part % --> (modulus division), return the remainder
What is the difference between ‘*’ and ‘**’?
- –> multiplication
* * –> power
The values passed to the function.
Arguments
What are the four ways to import sqrt() from math:
1- from math import sqrt
2- import math –> math.sqrt()
3- import math as m –> m.sqrt()
4- from math import ∗ (imports all functions, but it is not recommended)
Formatting:
age = 18
num=1
print( f “Im { age } today ” )
print(f“ Cost {age + num}”)
Formating
look w-8a Page-8 to 11 VERY IMPRTANT INFO
Strings are right justified by default
TRUE OR FALSE?
FALSE
num > num2 + 1
The comparison operators have higher precedence than arithmetic operators?
TRUE OR FALSE?
FALSE
Calculations are done before the comparison
How to print ‘’ or ‘?
’ “ ‘ OR “ ‘ “. They must be opposite
What will be printed?
name = ‘Rand’ + ‘AB’
name2 = ‘Rand’, ‘AB’
name = RandAB name2 = Rand AB
What is concatenating strings?
str1 + str2
using (+) to connect strings
a sequence of characters used inside a
string literal that translates into another character
An escape sequence ()
\n
\t
\
Can you use (< or >, like str[1] > str[2]) with letters?
Yes.
space then numbers then uppercase then lower
Method vs Function
Unlike a function, a method can only be applied to an object
of the type for which it was defined
Methods are specific to a type of object
String methods:
upper() and lower()
replace(old, new) ->
Ex: name . r e p l a c e ( “ ohn ” , “ames ” )