In Python we don’t specify what kind of data we are going to put in a variable. So you can directly write abc = 1 and abc will become an integer datatype. If you write abc = 1.0 abc will become of floating type. Here is a small program to add two given numbers

>>> a=13>>> b=23>>> a+b36

From the above example you can understand that to declare a variable in Python , what you need is just to type the name and the value. Python can also manipulate strings They can be enclosed in single quotes or double quotes like

Generally the real life Python codes do not need to read input from the keyboard. In Python we use input function to do input. input(“String to show”) , this will return a string as output. Let us write a program to read a number from the keyboard and check if it is less than 100 or not. Name of the program is testhundred.py

#!/usr/bin/env python3number=int(input("Enter an integer: "))ifnumber<100:print("Your number is smaller than 100")else:print("Your number is greater than 100")

The output

$ ./testhundred.py
Enter an integer: 13
Your number is smaller than 100
$ ./testhundred.py
Enter an integer: 123
Your number is greater than 100

You can even assign values to multiple variables in a single line, like

>>> a,b=45,54>>> a45>>> b54

Using this swapping two numbers becomes very easy

>>> a,b=b,a>>> a54>>> b45

To understand how this works, you will have to learn about a data type called tuple. We use comma to create tuple. In the right hand side we create the tuple (we call this as tuple packing) and in the left hand side we do tuple unpacking into a new tuple.

F-strings provide a simple and readable way to embed Python expressions in a
string. Here are a few more examples.

>>> answer=42>>> print(f"The answer is {answer}")The answer is 42>>> importdatetime>>> d=datetime.date(2004,9,8)>>> f"{d} was a {d:%A}, we started the mailing list back then."'2004-09-08 was a Wednesday, we started the mailing list back then.'

If you want to know more about how this feature came into Python, watch this
talk from Mariatta Wijaya.

pym is a book to learn Python.
It targets people who are completely
new to the language.