×

To install this app on your iPhone, tap Share 🔗 then Add to Home Screen.

06 Introduction to Python Variables

0
62

Basically, Python has no command to Declare a Variable. A Variable is created as soon as you assign any value to it. Whether it is numeric, String, Float, Boolean or any kind.

Variables do not need to be declared with any particular type, and can even change type after they have been set.

*** Variable names in Python are case-sensitive.

A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume)

Following are some rules to create a variable name:

  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive (age, Age and AGE are three different variables)

Example 01:

x = 5
y = "John"
print(x)
print(y)

Example 02:

x = 4       # x is of type int
x = "Sally" # x is now of type str
print(x)

Example 03:

x = str(3)    # x will be '3'
y = int(3)    # y will be 3
z = float(3# z will be 3.0

type() function:

You can get variable type using type() function.

Example:

x = 5
y = "John"
print(type(x))
print(type(y))

Căutare
Categorii
Citeste mai mult
Food
Beyond Basic Baking: Exploring the Expanding Functional Flour Industry
The global food industry is undergoing a significant transformation, driven by health-conscious...
By Ava Thomas 2025-05-21 09:11:20 0
Food
4 Knockout Ravioli Sauces That'll Make Your Perth Dinners Sing (Tommy Sugo's Secret Recipes!)
  G'day Perth Pasta Lovers! Let's be real - ravioli without a proper sauce is like a beach...
By Asif Asif 2025-05-21 13:20:52 0
Information Technology
タイヤ熱分解油世界市場調査レポート:規模、成長戦略、トレンド予測2025-2031
タイヤ熱分解油世界総市場規模...
By Qyresearch Jasmine1 2025-05-19 03:02:05 0
Alte
Water Treatment Ozone Generator Market Benefits from Smart Treatment
Water Treatment Ozone Generator Market grows with rising demand for eco-friendly, chemical-free...
By Lisa Tate 2025-05-27 13:01:06 0
Alte
Importance of Backend Development in Mobile Apps
When we talk about mobile apps, most people instantly think about the flashy user interfaces,...
By Dharani Dhara 2025-05-31 08:30:49 0