WHAT IS PYTHON INHERITANCE?
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?
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?
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?
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?
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?
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?
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?
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?
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?
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?
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?
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 […]
WHAT IS THE STRING TYPE IN 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 […]
WHAT ARE THE NUMERIC TYPES IN 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 […]
WHAT ARE THE DATA TYPES IN 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 = […]
WHAT IS THE GLOBAL VARIABLE IN 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 […]
WHAT IS THE VARIABLE IN 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 […]
HOW TO PRINT IN 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) […]
WHAT IS THE PYTHON SYNTAX?
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 […]
HOW TO INSTALL PYTHON AND EXECUTE PROGRAM?
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 […]