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
Alte
How to Propose in Bengali
How to Express Love and Propose Someone in Bengali – A Heartfelt Guide Looking for the best...
By Technology Welldone 2025-07-01 16:49:14 0
Alte
Middle East and Africa Industrial IoT Market Outlook: Growth, Share, Value, Size, and Trends
"Executive Summary Middle East and Africa Industrial IoT Market : CAGR Value Data...
By Shweta Kadam 2025-07-08 05:55:41 0
Crafts
Taste Meets Technology: Synthetic Food Colors Market Expands to Meet Visual Appeal Trends
"Executive Summary Synthetic Food Colors Market :  Data Bridge Market Research...
By Komal Galande 2025-07-01 04:57:09 0
Alte
Basic STCW Safety Training
Comprehensive Maritime Training Courses | R PSCRB, STCW, Security & Survival Craft Training...
By Technology Welldone 2025-06-19 04:42:05 0
Alte
多目的フリゲート艦の最新調査レポート:市場規模、競合環境、成長要因2025
QYResearch株式会社(所在地:東京都中央区)は、最新の調査資料「多目的フリゲート艦―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」を2025年7月11日より...
By Zhang Weixuan 2025-07-11 07:30:42 0
Omaada - A global social and professionals networking platform https://www.omaada.com