×

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
Hire a Photo Studio
Hire a Photo Studio in Bangalore – Professional & Affordable Studio Spaces If you are...
Par Business Maker 2025-06-10 09:18:59 0
Domicile
Is Your Home Really Safe? Discover the Basics of Home Security
Your home is your sanctuary—and keeping it secure should always be a top priority. While...
Par Jason Watsom 2025-06-06 18:57:04 0
Sports
newslilla
Stay updated with the latest happenings in entertainment, politics, and sports at...
Par Newslilla Newslilla 2025-05-19 07:21:09 0
Autre
China Solar Water Pumps Market: Innovation, Efficiency, and Growth Outlook
China Solar Water Pumps Market: Trends, Drivers, and Future Outlook The China solar water pumps...
Par Reshama Patil 2025-06-11 06:52:01 0
SEO
ISO 27001-Zertifizierung
Überblick über die ISO 27001-Zertifizierung Eine ISO 27001-Zertifizierung ist eine...
Par Bexon Liv 2025-06-02 12:38:52 0