Saraswat World

WHAT IS PYTHON INHERITANCE?

WHAT IS PYTHON INHERITANCE?

Python

PYTHON INHERITANCE Inheritance is a mechanism of object-oriented programming for deriving new classes (sub classes) from existing ones such as super class or base class. It allows us to define a class that inherits all the methods and properties from another class. Parent class or base class, is the class being inherited from. Child class […]

WHAT IS PYTHON CONSTRUCTOR?

WHAT IS PYTHON CONSTRUCTOR?

Python

PYTHON CONSTRUCTOR- A constructor is a special type of method or function that is used to initialize the instance members of the class. Constructor definition is automatically executed when we create the object of the class. Constructors also verify that there are enough resources for the object to perform any start-up task. The _init_() method simulates […]

WHAT IS A CLASS AND OBJECT IN PYTHON?

WHAT IS A CLASS AND OBJECT IN PYTHON?

Python

DEFINITION OF PYTHON CLASS AND OBJECT Python Class The Class is a logical entity that has some attributes and methods, in other words, we can also say that the class is like an object constructor or a โ€œblueprintโ€ for creating objects. Python Objects The Object is an entity that has a state and behavior. HOW […]

WHAT ARE LAMBDA FUNCTIONS IN PYTHON?

WHAT ARE LAMBDA FUNCTIONS IN PYTHON?

Python

Definition of Python Lambda Functions Lambda Functions are anonymous or unnamed short functions. Syntax of Lambda Functions in Python Examples of Python Lambda Functions Lambda function with single argument Code Output Lambda function with multiple arguments Lambda functions can take any number of arguments Code output

HOW TO USE FUNCTIONS IN PYTHON?

HOW TO USE FUNCTIONS IN PYTHON?

Python

WHAT IS A FUNCTION IN PYTHON? A function is a named sequence of statements or a block of code that only runs when it is called by its name. We can pass data, known as parameters, into a function. On calling a function it will execute the block of code and can return data as […]

HOW TO USE FOR LOOPS IN PYTHON?

HOW TO USE FOR LOOPS IN PYTHON?

Python

A For loop is used to execute a set of statements, once for each item in a list, tuple, set, dictionary, string, or any iterable object, etc. As shown in below example it will print each fruit available in the list output The break Statement The break statement is used to stop the loop before […]

HOW TO USE WHILE LOOP IN PYTHON?

HOW TO USE WHILE LOOP IN PYTHON?

Python

The while Loop While loop is used to execute a set of statements as long as the provided condition is true, as shown in below example that i will be printed as long as i is less than 5 output The break Statement The break statement is used to stop the loop even if the […]

HOW TO USE IF ELSE IN THE PYTHON?

HOW TO USE IF ELSE IN THE PYTHON?

Python

Using the if keyword in the Python Syntax- if <Logical_Condition>: <if_block> When <Logical_Condition> returns True value then the code given in <if_block> will execute as shown in below example- Output Using the Elif keyword in the Python The Elif keyword is used to provide another Logical Condition in case the previously provided condition is not […]

WHAT IS LIST IN PYTHON?

WHAT IS LIST IN PYTHON?

Python

LIST DEFINITION- A LIST is basically a data structure consisting of a collection of any datatype ordered, changeable, and indexed elements or items, created by enclosing elements in square brackets or by using List() constructor. List items allow duplicate values and its first item has index [0]. Properties of List items- Orderedโ€“ List items have […]

WHAT ARE SETS IN PYTHON?

WHAT ARE SETS IN PYTHON?

Python

SETS DEFINITION- A set is basically a data structure consisting of a collection of any datatype unordered, unique, unchangeable, and unindexed elements, created by enclosing elements in curly braces or a set constructor.Note-Set items are unchangeable, but you can remove and/or add items HOW TO CREATE A SET IN PYTHON? By using curly braces Python […]

WHAT IS A DICTIONARY IN PYTHON?

WHAT IS A DICTIONARY IN PYTHON?

Python

DICTIONARIES A dictionary is a mapping of keys to values. Itโ€™s also sometimes called a hash table or associative array. The keys serve as indices for accessing values. Dictionaries are written with curly brackets as shown in the below examples. Dictionaries in python are used to store data values in key: value pairs each pair […]

HOW TO USE TUPLE IN PYTHON?

HOW TO USE TUPLE IN PYTHON?

Python

TUPLE A Tuple is an ordered and unchangeable collection of python objects, each object is separated by a comma and the whole set is enclosed by parenthesis. Tuples allow duplicate values. PROPERTIES OF TUPLE Tuple items or objects are ordered, unchangeable, and allow duplicate values. Tuple items are indexed, the first item has an index [0], the […]

Strings in Python

WHAT IS THE STRING TYPE IN PYTHON?

Python

STRINGS in python are arrays of bytes representing Unicode characters, in python syntax string is represented by enclosing characters in single or double quotes for one liner statement. And Multiline strings are represented by enclosing it in three double or three single quotes. Example Code a=โ€™Hello Worldโ€™print(a)b=โ€Hello Worldโ€print(b)c=โ€โ€โ€This is multilinestring statement!โ€โ€โ€print(c)d=โ€โ€™This is multilinestring statement!โ€โ€™print(d)print(a[0],a[1]) Output Hello […]

NUMERIC TYPES IN PYTHON

WHAT ARE THE NUMERIC TYPES IN PYTHON?

Python

NUMERIC DATA TYPES Python uses following three types of numeric data types. type() function in Python is used to get data type of object. Data Type Examples Output Description int x=1 print(type(x)) <class โ€˜intโ€™> Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length. float x = 3.5 print(type(x)) <class […]

DATA TYPES IN PYTHON

WHAT ARE THE DATA TYPES IN PYTHON?

Python

Python has the following data types built-in by default. Variable can store data of different types as per requirements. Categories Data Type Example Text str x = โ€œBe Happyโ€ Numeric int x = 1 Numeric float x = 3.5 Numeric complex x = 1j Sequence list x = [โ€œAโ€, โ€œBโ€, โ€œCโ€] Sequence tuple x = […]

Global Variable in Python

WHAT IS THE GLOBAL VARIABLE IN PYTHON?

Python

Global Variables in python are the Variables that are created outside of a function. Global variables can be used anywhere by everyone within the program. To create a global variable inside a function, you can use the โ€œglobalโ€ keyword and its scope will be global. Example- x=โ€globalVariable1โ€ณ     #variable declaration y=โ€globalVariable2โ€ณ     #variable declaration def […]

Variable in Python

WHAT IS THE VARIABLE IN PYTHON?

Python

Python variables are the reserved memory locations used to store values with in a Python Program. A variable in Python is created the moment you first assign a value to it. Variables in Python do not need to be declared with any particular type, and can even change type after they have been set. If […]

Print in Python

HOW TO PRINT IN PYTHON?

Python

โ€ขprint function,which writes to standard out. Standard out is where the computer writes its output. โ€ขStrings or characters are enclosed in inverted commas. print(โ€œhello worldโ€) โ€ขOutput of above statement. hello world โ€ขTo print out multiple items, you can provide them separated by commas. You can put strings and numbers in a print function. print(โ€œmyโ€,โ€program no.โ€,1) […]

Python Syntax

WHAT IS THE PYTHON SYNTAX?

Python

Python syntax defines a set of rules that are used to create Python statements while writing a Python Program. Case sensitivity in Python-  Case sensitivity in Python is applicable as python is a case sensitive programming language. Indentation in Python- Indentation in Python is used to indicate a block of code, all statements within the […]

Install and Execute Python

HOW TO INSTALL PYTHON AND EXECUTE PROGRAM?

Python

To check if you have python installed on a Windows PC, run the following command on the Command Line (cmd.exe)- python โ€“version   If you find that you do not have Python installed on your computer,   then you can download it from website: https://www.python.org/ To execute the program first save the code in the text editor […]