Variables and Data Types in Python
What is a variable in Python?
A Variable is a container for a value. Behaves as the value it contains. (See below.) A variable is a name that refers to a value stored in memory. (Ex.): First_name = "Sky" Value will always have " " around it, if it's text. if it's a number, then you can put just the number like this... (Ex.): Age = 30
What is the floating-point data type in Python?
A float represents a real number and includes a decimal point. Example: pi = 3.14 assigns a float value to the variable pi.
What is the list data type in Python?
A list is an ordered, mutable sequence of elements. Example: grades = [90, 85, 77] assigns a list to the variable grades.
What is the string data type in Python?
A string is a sequence of characters enclosed in quotes. Example: name = "Alice" assigns a string value to the variable name.
What is the tuple data type in Python?
A tuple is an ordered, immutable sequence of elements. Example: coordinates = (4, 5) assigns a tuple to the variable coordinates.
What is the integer data type in Python?
An integer is a whole number without a fractional part. Example: count = 100 assigns an integer value to the variable count.
What is the boolean data type in Python?
Boolean data type represents the truth values True and False. Example: is_happy = True assigns a boolean value to the variable is_happy.
What is the complex data type in Python?
Complex numbers consist of a real and imaginary part. Example: z = 3 + 4j assigns a complex value to the variable z.
What is the None data type in Python?
None represents the absence of a value or a null value. Example: result = None assigns the None value to the variable result.
What is type conversion in Python?
Type conversion refers to the conversion of one data type into another. int() - converts any data type into integer type float() - converts any data type into float type ord() - converts characters into integer hex() - converts integers to hexadecimal oct() - converts integer to octal tuple() - This function is used to convert to a tuple. set() - This function returns the type after converting to set. list() - This function is used to convert any data type to a list type. dict() - This function is used to convert a tuple of order (key,value) into a dictionary. str() - Used to convert integer into a string. complex(real,imag) - This functionconverts real numbers to complex(real,imag) number.