Programming Flashcards
1
Q
Arithmetic operations
A
- subtraction = a-b
- multiplication = a*b
- real/float division = a/b
- integer division, including remainders = a//b a%b
- exponentiation = a**b
- rounding = round(number, digits)
- truncation = file.truncate(size)
2
Q
Boolean operations
A
- NOT
- AND
- OR
- XOR
3
Q
Relational operators
A
- equal to = a==b
- not equal to = a!=b
- less than = a<b
- greater than = a>b
- less than or equal to = a<=b
- greater than or equal to = a>=b
4
Q
The difference between a variable and a constant
A
Variables values can be changed and updated., whereas constants values cannot be changed or updated
5
Q
Advantages of using named constants
A
-make the code easier to understand and modify
-reduce errors from unexplained numerical values
-allow for faster and more efficient code execution due to compiler optimization
6
Q
String handling operations
A
- length = len(string)
- pos of char/ss = string.index(substring)
- character at position = string[x]
- substring = string[x:y]
- concatenation =(a,b = “a b”) (a+b = “ab”)
- character → character code = ord(character)
- character code → character = chr(char code)
7
Q
String conversion operations
A
- string to integer = int(string)
- string to float = float(string)
- integer to string = str(integer)
- float to string = str(float)
- date/time to string = strftime()
- string to date/time = datetime.strptime(date_string, format)
8
Q
Random number generation
A
import random
* random number = random.randint(x,y)