This tutorial covers basics of Python Programming Language. It has been specifically designed for beginners and students of computer science and informatics practices.
Lessons
Installing Python IDLE | Downloading Python IDLE and Installation
PreviewUsing Python IDLE | Python Programming in Python IDLE
PreviewUsing Python IDLE | Python Programming in Python IDLE After installing Python IDLE, we can type and run Python commands Using Python IDLE. How To Run Python Commands Using Python IDLE Click at start Menu-> All Programs-> Python 3.6 ->IDLE (Python 3.6 32 Bit). IDLE may be different depending upon the version of Python installed …
Installing Anaconda | Download Anaconda and Installation
PreviewInstalling Anaconda | Download Anaconda and Installation What is Anaconda Anaconda distribution of Python is best for Python programmers. It is free and can be easily downloaded and installed on your computer. Anaconda comes with pre-installed packages including NumPy, Matplotlib and SymPy etc. How to download Anaconda Open website https://www.anaconda.com/distribution/ from your web browser. Click …
Using Anaconda Navigator | Python using Anaconda Navigator
PreviewUsing Anaconda Navigator | Python using Anaconda Navigator Anaconda Navigator is a graphical user interface (GUI application that allows you to launch different applications and easily manage conda packages without using command-line commands. It can also search for packages on Anaconda Cloud or in a local Anaconda directory. It can work with Windows, macOS as …
Introduction to Python | Basic Python Components
PreviewIntroduction to Python | Basic Python Components Python is an object oriented Programming Language developed by Guido Van Rossum in February 1991. It is basically influenced from two languages namely ABC and Modula-3. Why it is named Python Python is not named after snake but is named after famous BBC comedy show “Monty Python’s Flying …
Literals in Python
PreviewLiterals in Python Literal may be defined as a quantity whose value can’t be changed during the execution of a Program. So values of Python Literals don’t change during execution of program. Types of Python Literals Python Literals are categorized into five types as: 1. String literals 2. Numeric Literals 3. Boolean 4. None 5. …
Data types in Python
PreviewData types in Python Data type specifies the type of data as well as the range of values that can be stored in the data object . Different Data types in Python 3 are as follows: String Numeric Boolean None Collections 1. String Data Type in Python In Python, string is the collection of multiple …
Working with variables in Python | How to use variables in Python
PreviewWorking with variables in Python | How to use variables in Python A variable in Python represents named location that refers to a value and whose values can be used and processed during program run. Example : Name=”Lovejot” Percentage=91 There are two variables Name and Percentage with values “Lovejot” and 91 respectively. Create a Variable …
Display output in Python 3 | print() function in Python 3
PreviewDisplay output in Python 3 | print() function in Python 3 We can use print() function in Python to display some message or output on Python shell. The Syntax of print function is: print(EXPRESSION) Here EXPRESSION is the variable of any data type or string value that we want to display. In previous versions of …
Read values in Python 3 | input() function in Python
PreviewRead values in Python using input() function. We can use input() function in Python to read some value at python shell. This function is basically used to read string value. The Syntax of input() function is: varname=input() Here varname is the name of variable that we want to read. 1. Reading string values using input() …
eval() function in Python 3
Previeweval ( ) Function in Python The eval ( ) function is used to convert a string value to numeric value. Example 1:. Convert string value to integer value >>> a=eval(’10’) >>> print(a) 10 >>> print(type(a)) <class ‘int’> Description eval() function converts string value ‘10’ into integer value 10. That is why type(a) is returned …
Basic operators in Python | Types of operators in Python
PreviewBasic operators in Python | Types of operators in Python Operator It is the symbol used to perform some calculation or manipulation on variables , literals or expressions. Operand It is the variable, literal or expression on which an operator performs some operation. Example: 9 + 8 In above expression, 9 and 8 are operands …
Augmented Operators in Python 3 | Assignment operators in Python 3
PreviewAugmented Operators in Python 3 | Assignment operators in Python 3 Augmented operators in Python are used to update the value of a variable in an easy way. There are seven assignment Operators in Python . 1. += It is used to add value of right operand to the left operand. Result will be stored …
2 types of Identity Operators in Python 3
Preview2 types of Identity Operators in Python 3 Identity operators in Python are used to verify whether two variables refer to same memory location or not. They are of two types: i. is operator: It returns true if two variables refer to same memory location. Example: a=10 b=10 print(a is b) Output is True as …
2 Types of Membership Operators in Python
Preview2 Types of Membership Operators in Python Membership operators in Python are used to check whether a value or variable is member of a sequence (String, List, Tuple, Dictionary or set). There are two types of membership operators : Operator Description Example in It returns true if a value or variable is member of a …
Arithmetic Operators in Python 3
PreviewArithmetic Operators in Python 3 Arithmetic operators are used to perform mathematical calculations in a program. Various Arithmetic Operators in Python 3 are: Operator Purpose Example + (Addition) To add two numeric quantities. 10+3=13 – (Subtraction) To subtract one numeric quantity from another. 10-3=7 * (Multiplication) To multiply two numeric quantities. 10*3=30 / (Division) To …
Relation between Equality(= =) and Identity (is) operators
PreviewRelation between Equality(= =) and Identity (is) operators We have seen that if values of two variables are same, a=10 b=10 a==b and a is b will return true But it is not always true. There are some cases where two variables have same value but they return different results. It happens because there are …
5 types of if Statement in Python
Previewif statement in Python is very powerful decision making statement used to control the flow of execution of statements. It is a two way decision making statement used with a relational or logical expression. It can be used in five ways: Simple if If else Nested if If else if ladder Single Line if 1. …
2 Types of Looping in Python (for, while, nested loop)
PreviewLooping statements in Python Looping statements are used to repeat same set of statements again and again for a specific number of times or depending upon a condition.There are two types of looping statements Python: for loop while loop 1. for loop for loop is basically used when we know how many times, a specific …
String in Python 3 | Manipulating strings in Python
PreviewWhat is a String in Python? String is a sequence of characters within the pair of single quotes(‘) or double quotes (“). Example: “school”, “Rs100”, ‘$24.50’,’father-name’. 1. Creating a String Variable To create a string variable, we need to put a string value into string variable using assignment operator Syntax: Stringvariable =”Value1” OR Stringvariable=’Value1’ …
string functions in python 3 with examples | string methods in Python examples
Previewstring functions in python 3 with examples Click here for Quiz on Functions in Python 1. capitalize() method in Python 3 capitalize() function in Python makes first character of string capital. Example >>> name=’lovejot’ >>> name.capitalize() ‘Lovejot’ #First character becomes capital 2. find() method in Python 3 find() method in Python is used to find …
Python List with Examples | List in Python 3
PreviewWhat is a List in Python? List is a collection of values within pair of square brackets. These values must be separated by commas. These values can be of any data type. Lists are mutable i.e. we can modify the elements of a list. 1. Creating a List To create a list, we can put …
List functions of Python | List Methods of Python
PreviewList functions of Python | List Methods of Python Python provides many predefined functions and methods for manipulation of list. 1. index() This method is used to find first index position of a value in a list. It returns-1 if value is not found in the list. Syntax: List.index (<Val>) List is user defined list. …
Python Tuple with Examples | Tuple in Python 3
PreviewPython Tuple with Examples | Tuple in Python 3 What is a Tuple in Python 3? Tuple is a collection of values within pair of parenthesis. These values must be separated by commas. These values can be of any data type. Tuples are immutable i.e. we can’t modify the elements of a tuple. 1. Creating …
Tuple functions in Python | Tuple methods in Python
PreviewTuple functions in Python | Tuple methods in Python 1. len() method This method returns number of elements in a tuple. Syntax: len(<tuple>) <tuple> refers to user defined tuple whose length we want to find. Example: >>> T1=(10,20,30,40) >>> len(T1) 4 #There are 4 element in tuple. 2. max() This method returns largest element of …
Python Dictionary with examples
PreviewPython Dictionary with examples What is a dictionary? A Dictionay is an unordered collections of elements in the form of key: value pairs separated by commas within the pair of braces(curly brackets). Example: {1:’a’,2:’b’,3:’c’} Characteristics of a Dictionary 1. Unordered Set Dictionary is an unordered set of key: value pairs i.e. Its values can contain …
Dictionary functions in Python | Dictionary methods in Python
PreviewDictionary functions in Python | Dictionary methods in Python 1. len() This method counts and returns number of elements (key:value pairs) in the dictionary. Syntax len(<dictionary>) <dictionary> refers to the user defined dictionary whose length we want to find. Example 1: >>> emp={‘name’:’Munish’,’age’:30,’designation’:’Teacher’} >>> len(emp) 3 Example 2: >>> emp={‘name’:’Munish’,’age’:30,’designation’:’Teacher’} >>> emp[‘subject’]=’Mathematics’ >>> emp {‘name’: …
Python Functions Tutorial | Using Functions in Python 3
PreviewUsing Functions in Python 3 Function is defined as the named group of statements which can be used to perform a specific task. A function in Python can contain one or more Python statements. When we call a function, all the statements written within the function body get executed on after another. Click here for …
Types of function in Python 3
PreviewTypes of function in Python 3 Python functions are categorized into three types: Click here for Quiz on Functions in Python 1. Built-in Functions in Python They are predefined functions provided by Python. They are also known as library functions. These functions are basically used to perform basic input/output operations and many other operations which …
Python Functions Tutorial | Types of function parameters in Python
PreviewTypes of function parameters in Python In Python, we can take four different types of parameters in a user defined function. They are as follows: Click here for Quiz on Functions in Python 1. Positional parameters in Python A positional parameter is any parameter that’s not supplied as a key=value pair. Value of first actual …
Python Modules and Packages
PreviewPython Modules and Packages Python module is defined as a collection of functions, variables, constants, classes, objects along with Python statements. Click here for Quiz on Modules and Packages Structure of a Python Module A Python module is a normal Python file (.py file) that can contain following things: (i) Docstring Docstring is text written …
Mathematical functions in python | math module in python
PreviewMathematical functions in python | math module in python Python has a variety of predefined functions . We do not need to import any module for them. So we use these functions of Python directly as: <function-name>() Example: input(), int(), float(), type(), len() etc. are predefined functions. Consider the following example program that uses some …
random module in python 3 | generate random number in python 3
Previewrandom module in python 3 | generate random number in python 3 Python has a predefined module random that provides random-number generator functions. A random number is a number generated randomly. To use random number generator functions in our Python program, we first need to import module random by using import statement as: import random …
statistics module in python 3 | statistical functions in python 3
Previewstatistics module in python 3 | statistical functions in python 3 Python has a predefined module statistics that provides statistical functions. To use statistical functions in our Python program, we first need to import module statistics by using import statement as: import statistics Most commonly used functions of this module are: mean() mode() median() i. …
Data file handling in python
PreviewData file handling in python What is a data file in Python A data file is a collection of data (bytes) stored on some storage device like hard-disk, CD, pen drive etc. Types of data file in Python There are two types of data files Text Files Binary Files 1. Text files in Python …
Steps to create data file in python
PreviewSteps to create data file in python 1. Opening a file Before working with data files in Python, the first thing is to open the file. We can use open( ) function to do it as: Syntax: <file_object> = open(<filename>) OR <file_object> = open(<filename> , <mode>) <file_object> is the file object used to read and …
Writing content into a file in python
PreviewWriting content into a file in python Different predefined functions of C language for writing content into file are: There are two predefined functions provided by Python to write data into a data file 1. write() write() function is used to write content into a data file.The syntax of write() function is: <fileobject>.write(str) Here fileobject …
Reading data from a file in python | read(), readline(), readlines() in Python
PreviewReading data from a file in python Different predefined functions of Python to read data from file are:: 1. read() method in Python This function is used to read entire content of file or specific number of characters from file. Syntax 1: <file_object>.read() Here file_object is the name of file handler object that is linked …
Removing Whitespaces after reading from File
PreviewRemoving Whitespaces after Reading from File read( ), readline( ), readlines( ) functions are used to read data from file. All these functions also read the leading (at beginning) and trailing (at ending) whitespaces i.e. spaces or tabs or newlines character. If we want to remove these trailing and leading whitespaces, we can use strip( …
Working with binary files in Python
PreviewWorking with binary file in Python Python provides the pickle module to write and read data from binary files. To work with the pickle module, we need to import it in our program using import statement as: import pickle We can use dump( ) and load ( ) methods of pickle module to write and …
How to Write data into a Binary File in Python | Writing data into a binary file using Python
PreviewHow to Write data into a Binary File in Python | Writing data into a binary file using Python To write an object to a binary file opened in the write mode, we should use dump( ) function of pickle module as per the following syntax : pickle.dump(<object>, <file-handler>) For example, if you have a …
How to Read data from a Binary File in Python | Searching record from a binary file in Python
PreviewHow to Read data from a Binary File in Python | Reading data from binary file in Python After writing data into binary file using dump() method of pickle module, we can read and display content of binary file load( ) method of the pickle module. Reading data from binary file is known as unpickling. …