
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Assigning Values to Variables in Python
Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.
Example
The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. For example −
#!/usr/bin/python counter = 100 # An integer assignment miles = 1000.0 # A floating point name = "John" # A string print counter print miles print name
Here, 100, 1000.0 and "John" are the values assigned to counter, miles, and name variables, respectively.
Output
This produces the following result −
100 1000.0 John
- Related Articles
- Assigning values to static final variables in java\n
- Assigning values to a computed property in JavaScript?
- How to assign values to variables in Python
- Assigning long values carefully in java to avoid overflow\n
- How do we assign values to variables in Python?
- Assign multiple variables with a Python list values
- How to assign values to variables in C#?
- Assigning function to variable in JavaScript?
- Assigning arrays in Java.
- How to create sequential index value for binary column assigning 0 to FALSE values in R data frame?
- How to create sequential index value for binary column assigning 0 to FALSE values in data.table object in R?
- New ways to Assign values to Variables in C++ 17 ?
- Assigning packages to delivery unit in SAP HANA
- Default values of static variables in C
- Private Variables in Python

Advertisements