Variables and Data Types
Swipe um das Menü anzuzeigen
Variables are a fundamental concept in Python, allowing you to store and refer to data by name. A variable acts as a label for a value in memory. In Python, you create a variable by assigning it a value using the equals sign (=). When naming variables, follow these rules:
- Variable names must start with a letter or underscore;
- Names can contain letters, numbers, and underscores;
- Variable names are case-sensitive;
- Avoid using Python reserved keywords as variable names.
Assigning a value to a variable is straightforward: write the variable name, then =, then the value you want to store.
12345678910111213# Assigning values to variables of different types # Integer variable age = 25 # Float variable temperature = 36.6 # String variable greeting = "Hello, Python!" # Boolean variable is_active = True
Python provides several built-in data types to represent different kinds of information. The most common are:
intfor whole numbers, such as25;floatfor decimal numbers, such as36.6;strfor text, such as"Hello, Python!";boolfor logical values, eitherTrueorFalse.
Each variable you assign is automatically given a data type based on the value you provide. The examples above show how to create variables with these types.
123456# Checking the data types of variables using type() print(type(age)) # Output: <class 'int'> print(type(temperature)) # Output: <class 'float'> print(type(greeting)) # Output: <class 'str'> print(type(is_active)) # Output: <class 'bool'>
Danke für Ihr Feedback!
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Variables and Data Types
Variables are a fundamental concept in Python, allowing you to store and refer to data by name. A variable acts as a label for a value in memory. In Python, you create a variable by assigning it a value using the equals sign (=). When naming variables, follow these rules:
- Variable names must start with a letter or underscore;
- Names can contain letters, numbers, and underscores;
- Variable names are case-sensitive;
- Avoid using Python reserved keywords as variable names.
Assigning a value to a variable is straightforward: write the variable name, then =, then the value you want to store.
12345678910111213# Assigning values to variables of different types # Integer variable age = 25 # Float variable temperature = 36.6 # String variable greeting = "Hello, Python!" # Boolean variable is_active = True
Python provides several built-in data types to represent different kinds of information. The most common are:
intfor whole numbers, such as25;floatfor decimal numbers, such as36.6;strfor text, such as"Hello, Python!";boolfor logical values, eitherTrueorFalse.
Each variable you assign is automatically given a data type based on the value you provide. The examples above show how to create variables with these types.
123456# Checking the data types of variables using type() print(type(age)) # Output: <class 'int'> print(type(temperature)) # Output: <class 'float'> print(type(greeting)) # Output: <class 'str'> print(type(is_active)) # Output: <class 'bool'>
Danke für Ihr Feedback!