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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Boolean operations

A
  • NOT
  • AND
  • OR
  • XOR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Random number generation

A

import random
* random number = random.randint(x,y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly