×

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
Games
YYGame娛樂首選|探索極致遊戲體驗的頂級平台
在現今數位娛樂蓬勃發展的時代,選擇一個安全穩定、內容豐富且回饋優渥的遊戲平台,是所有玩家追求的共同目標。而在眾多線上娛樂品牌中,YYGame...
By Imran Ali 2025-05-22 09:21:17 0
Other
What makes a laser engraving machine able to carve such precise and complex designs effortlessly?
Laser engraving machines have transformed the way many industries and creative fields produce...
By Hanzla Ali 2025-05-28 07:05:31 0
Other
Découvrez l’Inde autrement : guide complet pour un voyage sur‑mesure avec une agence de voyage en Inde francophone
Pourquoi choisir une agence de voyage en Inde francophone ? Organiser un voyage en...
By VoyageenInde CircuitsenInde 2025-05-19 10:29:53 0
Other
Boost Gambling Business Revenue with Better Ad Campaigns
In today’s competitive online and offline gambling market, creating a strategic advertising...
By Smith Jones 2025-06-04 09:45:09 0