Python Introduction
Python Introduction
It is used for:
software development,
mathematics,
system scripting.
Installing:
Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent
Python. Even some Windows computers (notably those from HP) now come with Python already
installed. If you do need to install Python and aren't confident about the task you can find a few
notes on the BeginnersGuide/Download wiki page, but installation is unremarkable on most
platforms.
Python Syntax:
As we learned in the previous page, Python syntax can be executed by writing directly in the
Command Line:
Hello, World!
pip install command: pip is a package manager which is written in Python language. It is used to
install and manage software packages. The pip install command is used to install any software
package from an online repository of public packages, called the Python Package Index. To run this
command in windows you need to open your Windows PowerShell and then use the following syntax
to install any package.
print command: print command is used to print a message on the screen or other standard output
device. The message can be a string or any other object. The print command can be used to print any
type of object like integer, string, list, tuple, etc.
Syntax: print(object)
type command: type command is used to check the type or class of an object.
Syntax: type(object)
range command: range command is used to generate a sequence of integers starting from 0 by
default to n where n is not included in the generated numbers. We use this command in for loops
mostly.
stop refers to the number before which you want to stop (Mandatory)
round command: round command is used to round a number to a given precision in decimal digits.
That means if you have so many digits after decimal in a float point number then you can use the
round command to round off the specified number. You can mention how many digits you want after
the decimal point.
digits refer to the count of digits you want after the decimal point. (Optional; By default 0)
input command: input command is used to take input from the user. The flow of the program will be
stopped until the user has entered any value. Whatever the user enters it will be converted into a
string by the input function. If you want to take an integer as input then you have to convert it
explicitly.
Syntax: input(message)
message refers to the text you want to display to the user. (Optional)
len command: len command or len() function is used to get the number of items in an object. If the
object is a string then len() function returns the number of characters present in it. If the object is a
list or tuple it will return the number of elements present in that list or tuple. len() gives an error if
you try to pass an integer value to it.
Syntax: len(object)
Loop commands: In python, we have two primitive loop commands namely while and for.
The while loop command is used to execute a set of statements as long as the given condition is
true.
Syntax of while loop: while condition:
statements
update iterator