×

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))

Search
Categories
Read More
Books and Authors
Inside the Hype: What Leaks Reveal About GTA 6's Next Evolution with MMOexp
The Grand Theft Auto franchise has long stood as a cornerstone of modern gaming culture. With...
By Anselm Rosseti 2025-06-07 08:56:26 0
Information Technology
鉄道絶縁材業界レポート:市場動向、機会分析、将来予測2025-2031
2025年6月3日に、QYResearch株式会社(所在地:東京都中央区)は「鉄道絶縁材―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最新調査資料を発行しました...
By Qyresearch Jasmine1 2025-06-03 09:15:36 0
Networking
Keeping UAE Safe: A Look at the Top Security Providers
In today’s fast-paced and ever-changing world, safety and security are more important than...
By Jorden Paul 2025-06-01 05:53:07 0
Other
Connected Car M2M Connections and Services Market Share, Size & Growth Forecast by 2034
The worldwide "Connected Car M2M Connections and Services Market" 2025 Research Report presents a...
By Tushar Jane 2025-05-14 05:20:04 0