PyAnWin/Python Variables and Data Types

Python Variables and Data Types
Python is a dynamically typed language, meaning you don't need to declare variables with a specific type. Python variables can hold values of any data type.

Variable Assignment
To assign a value to a variable, use the = sign: Variable names can contain letters, numbers and underscores. They cannot start with a number.

Data Types
Some common data types in Python:

Integers - Whole numbers like 1, 2, 3.

Floats - Decimal numbers like 1.5, 2.25.

Strings - Text values defined in quotes like "John"

Booleans - Logical values True or False.

Lists - Ordered sequence of values in []. Lists can hold different data types.

Tuples - Immutable ordered sequence of values in.

Dictionaries - Collection of key-value pairs in { }.

Type Conversion
You can convert between data types by using functions like int, float, str etc:

Checking Data Types
You can check the type of a value with the type function:

 num = 5 print(type(num)) # Prints </syntaxhighlight