Variables and Data types in Python

 

Python is a high-level, interpreted programming language that is popular for its simplicity, readability, and versatility. It is used for a variety of purposes, including web development, data analysis, scientific computing, and artificial intelligence. In this blog, we will cover some basic concepts of Python programming language.


Variables and Data types :

In Python, a variable is a container for storing data. Variables are created when they are first assigned a value. Python has several built-in data types, including strings, integers, floating-point numbers, and booleans. Variables can store any of these data types. 

For example:

name = "John"

age = 30

height = 1.75

is_student = True


Here, name is a string, age is an integer, height is a floating-point number, and is_student is a boolean.


Variable Names:

A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). 


Rules for Python variables 


  • 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).
  • A variable name cannot be any of the Python keywords.

Example:

myvar = "John"

my_var = "John"

_my_var = "John"

myVar = "John"

MYVAR = "John"

myvar2 = "John"



print(myvar)

print(my_var)

print(_my_var)

print(myVar)

print(MYVAR)

print(myvar2)


Output:

John

John

John

John

John

John



Comments

Popular posts from this blog

Unleashing the Power of Python Built-in Functions: A Comprehensive Guide

Python: An Introduction to the Popular, Versatile Programming Language

Mastering Python Modules: Enhancing Code Reusability and Modularity