General Basic Python Flashcards

1
Q

What are some built-in python data types?

A

Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType

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

How would you change the type of a variable?

A
  • You can Casting to change the type of a variable.
  • Casting in python is therefore done using constructor functions:
  • int()- constructs an integer number from an integer literal, a float literal (by removing all decimals), or a string literal (providing the string represents a whole number)
  • float() - constructs a float number from an integer literal, a float literal or a string literal (providing the string represents a float or an integer)
  • str() - constructs a string from a wide variety of data types, including strings, integer literals and float literals
How well did you know this?
1
Not at all
2
3
4
5
Perfectly