×

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

Rechercher
Catégories
Lire la suite
Autre
Pet Dietary Supplements Market Share, Size & Growth Forecast by 2034
Global Pet Dietary Supplements Market: Industry Trends, Share, Size, Growth, Opportunity and...
Par ASHWINI GOURKHEDE 2025-05-06 05:02:17 0
Health
Everything You Should Know Before Taking Vidalista
Erectile dysfunction (ED) affects millions of men worldwide, impacting not just their physical...
Par Ariana Collins 2025-05-21 05:34:57 0
Autre
プラスチック用赤リン難燃剤の最新市場動向:業界成長率、競争環境、今後の見通し2025-2031
YH Research株式会社(本社:東京都中央区)は、「グローバルプラスチック用赤リン難燃剤のトップ会社の市場シェアおよびランキング...
Par Krystal Lin 2025-06-06 06:25:53 0
Health
Citric acid
Citric acid - benefits and price Citric acid is a natural organic compound that is used as a food...
Par Natural Chemist8 2025-06-07 12:39:09 0
Autre
Cryptocurrency Exchange Platforms Market Size, Share & Trend Analysis 2025-2034
The most recent report published by Vantage Market Research indicates that the "Cryptocurrency...
Par ASHWINI GOURKHEDE 2025-05-16 05:30:53 0