Learn any programming language, “Hello, World!” is the first and simplest program you can begin with. It’s a simple program that prints Hello World! on the standard output device (screen).
When we run the program, the output will be:
We have used the built-in print() function to print Hello, world! string.
Variables in Python
Variables are reserved memory allocation to store values. It means when we declare a variable, we reserve some space in memory. Depending on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Integer, Decimal or character are various kinds of datatype.
Declarations in Python happen automatically when you apply value to a variable. Equal sign = is used to assign values to a variable. The operand to the Left-hand side of the = operator is the name of the variable and the operand to the right of the operator is the value to be stored in the variable.
Variables are mutable. Hence, the value of a variable can always be updated or replaced.
There are certain rules we have to follow when picking the name for a variable:
- The name can start with an upper or lower case alphabet.
- Variables can have numbers in between but not at the beginning.
- The _ character can appear anywhere in the name.
- Spaces are not allowed. Instead, we must use snake_case to make variable names readable.
- The name of the variable should be something meaningful that describes the value it holds, instead of being random characters.
Python’s Data Types
Python does not place a strong emphasis on defining the data type of an object.
The language provides three main data types:
Numbers in Python
Integers data types comprise of Positive and Negative Whole numbers. Amount occupied depends on the value assigned to the variable.
print(100) # A positive integer
print(-500) # A negative integer
num = 123456789 # Assigning an integer to a variable
num = -29000 # Assigning a new integer to existing variable
Float Data Type
Floating-point numbers or float refer to positive and negative decimal numbers. Python allows you to create decimals up to the very high decimal place. A float occupies 24 bytes of memory.
print(1.0000000999) # A positive float
print(-99.99) # A negative float
flt_pt = 1.23456789