Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Declare a Variable in Python

How to Declare a Variable in Python

Posted on January 10, 2025January 10, 2025 By Rishabh saini No Comments on How to Declare a Variable in Python

Declare a Variable in Python

Python is a dynamically typed language, meaning you don’t need to specify the variable type or declare it before using it. This feature makes Python one of the most efficient and user-friendly programming languages. In Python, every variable is treated as an object, which simplifies coding and enhances flexibility.

Complete Python Course with Advance topics:-Click here

Before declaring variables in Python, you should follow these essential rules:

Rules for Declaring Variables:

  1. The variable name must begin with an underscore (_) or an alphabet.
  2. In variable names, special characters like @, #, %, ^, &, and * are not permitted.
  3. Variable names are case-sensitive. For example, age and AGE are treated as two different variables.
  4. Reserved keywords cannot be used as variable names. For instance, if, while, class, and def are reserved words in Python.

Now, let’s explore how to declare some basic variables.

Declaring Numbers in Python

Python supports three main types of numbers:

  • Integer
  • Floating-point numbers
  • Complex numbers

Python allows variables of any length, without restrictions. Here’s how to use and declare variables of the integer type:

num = 25  
print("The type of num:", type(num))  
print(num)  
  
float_num = 12.50  
print("The type of float_num:", type(float_num))  
print(float_num)  
  
complex_num = 2 + 5j  
print("The type of complex_num:", type(complex_num))  
print("Is complex_num a complex number?", isinstance(complex_num, complex))  

Output:

The type of num: <class 'int'>
25
The type of float_num: <class 'float'>
12.5
The type of complex_num: <class 'complex'>
Is complex_num a complex number? True

Declaring Strings in Python

Strings are sequences of Unicode characters in Python. Strings can be declared with single, double, or triple quotations. Here’s an illustration:

str_var = 'UpdateGadh'  
print(str_var)  
print(type(str_var))  
  
str_var1 = "Welcome to UpdateGadh"  
print(str_var1)  
print(type(str_var1))  
  
str_var2 = '''This is a string  
using triple  
quotes'''  
print(str_var2)  
print(type(str_var2))  

Output:

UpdateGadh
<class 'str'>
Welcome to UpdateGadh
<class 'str'>
This is a string
using triple
quotes
<class 'str'>

Multiple Assignments in Python

1. Assigning Multiple Values to Multiple Variables

Python allows assigning multiple variables on the same line. Here’s how:

x, y = 10, 20  
print(x, y)  

Output:

10 20

In the same order, the values are assigned and printed.

2.Giving Several Variables a Single Value

Additionally, you can give several variables the same value at once:

a = b = c = "UpdateGadh"  
print(a)  
print(b)  
print(c)  

Output:

UpdateGadh
UpdateGadh
UpdateGadh

Download New Real Time Projects :-Click here


python declare a variable in python without value
what is variable in python with example
python declare variable type
types of variables in python with example
rules for naming variables in python
data types in python
variables in python w3schools
what is a variable
for loop python
Declare a Variable in Python
declare an empty variable in python
declare a variable in python example
declare a variable in python w3schools

Post Views: 667
Python Interview Question Tags:declare variables in python, how to create a variable in python, how to declare a variable in python, how to define a variable in python, learn python, Python, python for beginners, python global variables, python printing variables, python programming, Python Tutorial, python tutorial for beginners, python variable declaration, python variables, variable in python, variables in python, variables in python in hindi, variables python

Post navigation

Previous Post: Student Attendance Management System using python Django
Next Post: How to render web page into Django

More Related Articles

Python vs Scala Python vs Scala Python Interview Question
How to Create a DataFrame in Python How to Create a DataFrame in Python Python Interview Question
How to Convert Text to Speech in Python How to Convert Text to Speech in Python Python Interview Question

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. How to Install Python on Windows: A Step-by-Step Guide
  2. How to Run Python Program: A Comprehensive Guide for Python Programmers
  3. How to Append Elements to a List in Python
  4. How to Install Matplotlib in Python
  5. How to Create a DataFrame in Python
  6. Insertion Sort in Python

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,612)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,210)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,866)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme