Hi there, we’re Harisystems

"Unlock your potential and soar to new heights with our exclusive online courses! Ignite your passion, acquire valuable skills, and embrace limitless possibilities. Don't miss out on our limited-time sale - invest in yourself today and embark on a journey of personal and professional growth. Enroll now and shape your future with knowledge that lasts a lifetime!".

For corporate trainings, projects, and real world experience reach us. We believe that education should be accessible to all, regardless of geographical location or background.

1
1

Python Variables

Variables are essential elements in any programming language, including Python. They serve as containers for storing data values. In Python, variables are dynamically typed, which means that you don't need to declare the variable type explicitly.

Variable Declaration and Assignment

In Python, you can declare a variable and assign a value to it in a single line using the following syntax:

    variable_name = value
  

Here's an example:

    x = 5
  

In the example above, we declared a variable named "x" and assigned the value 5 to it.

Variable Naming Rules

When naming variables in Python, you need to follow certain rules:

  • Variable names must start with a letter (a-z, A-Z) or an underscore (_).
  • Variable names can only contain letters, numbers, and underscores.
  • Variable names are case-sensitive. For example, "myVariable" and "myvariable" are considered different variables.
  • Variable names should be descriptive and meaningful to enhance code readability.

Example:

    name = "John"
age = 25
is_student = True
  

In the above example, we declared three variables:

  • name: This variable stores the string "John".
  • age: This variable stores the integer value 25.
  • is_student: This variable stores the boolean value True.

Variable Reassignment

In Python, you can change the value stored in a variable by assigning a new value to it. For example:

    x = 5
x = 10
  

After the above code snippet executes, the variable "x" will hold the value 10 instead of 5.

Using Variables in Expressions

Variables are commonly used in expressions to perform calculations or manipulate data. Here's an example:

    radius = 5
pi = 3.14159
area = pi * radius ** 2
  

In the example above, we calculated the area of a circle using the formula "pi * r^2". The variable "area" stores the result of the calculation.

Conclusion

Python variables are versatile tools for storing and manipulating data. By understanding variable declaration, naming rules, reassignment, and usage in expressions, you can effectively utilize variables to enhance the functionality of your Python programs.

4.5L

Learners

20+

Instructors

50+

Courses

6.0L

Course enrollments

4.5/5.0 5(Based on 4265 ratings)

Future Trending Courses

When selecting, a course, Here are a few areas that are expected to be in demand in the future:.

Beginner

The Python Course: Absolute Beginners for strong Fundamentals

By: Sekhar Metla
4.5 (13,245)
Intermediate

JavaScript Masterclass for Beginner to Expert: Bootcamp

By: Sekhar Metla
4.5 (9,300)
Intermediate

Python Coding Intermediate: OOPs, Classes, and Methods

By: Sekhar Metla
(11,145)
Intermediate

Microsoft: SQL Server Bootcamp 2023: Go from Zero to Hero

By: Sekhar Metla
4.5 (7,700)
Excel course

Future Learning for all

If you’re passionate and ready to dive in, we’d love to join 1:1 classes for you. We’re committed to support our learners and professionals their development and well-being.

View Courses

Most Popular Course topics

These are the most popular course topics among Software Courses for learners