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
コンベアベルト状態監視システム市場規模予測:2031年には346百万米ドルに到達へ
2025年7月21日に、QYResearch株式会社(所在地:東京都中央区)は、「コンベアベルト状態監視システム―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の最...
Par Qyresearch Jasmine1 2025-07-21 02:15:44 0
Autre
Herringbone Vinyl Flooring
Premium Herringbone Vinyl Flooring in Singapore – Elegant Style Meets Practicality...
Par Technology Welldone 2025-07-20 14:06:40 0
Autre
Cobalt Market Size, Share, Trends, Demand, Growth and Competitive Outlook
Executive Summary Cobalt Market : Global cobalt market size was valued at USD 12.42...
Par Nshita Hande 2025-07-07 05:29:05 0
Autre
露光ステッパーの最新調査レポート:市場規模、競合環境、成長要因2025
2025年7月9日に、QYResearch株式会社(所在地:東京都中央区)は、「露光ステッパー―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の調査資料を発行しまし...
Par Liu Yuan 2025-07-09 03:48:23 0
Tutorials
Pet Food Flavors and Ingredients Market Set to Expand as Demand for Natural and Functional Products Surges
"Executive Summary Pet Food Flavors and Ingredients Market :  Data Bridge Market...
Par Komal Galande 2025-06-23 03:44:36 0
Omaada - A global social and professionals networking platform https://www.omaada.com