Python

  • WHAT IS DATETIME MODULE IN PYTHON?

    Python Datetime Module Python Datetime Module in Python provides us the different features to work with dates as date object by importing the datetime module. Current Date Python code to import the datetime module to access current date output (Note-it will show the current date and time, at the time of execution of code on your machine)…

  • WHAT IS POLYMORPHISM IN PYTHON?

    PYTHON POLYMORPHISM Polymorphism is one of the OOP(object-oriented programming) concepts. Polymorphism in Python is the ability of an object to take many forms. The word “polymorphism” means “many forms”, and in programming, it refers to methods/functions/operators with the same name that can be executed on many objects or classes. Function Polymorphism in Python In Python…

  • WHAT IS A PYTHON MODULE?

    PYTHON MODULE Module is a file or library of codes or set of methods, that can be included in our Application. HOW TO CREATE A MODULE? Creating Module- Module can be created by saving the code in a file with the file extension .py. Python Code- Save below code in file named mymodule.py Using Module-…

  • WHAT IS PYTHON ITERATOR?

    PYTHON ITERATORS An Iterator is an object that contains a countable no. of values or elements that can be traversed. An iterator allows a programmer to traverse through all the elements of a collection or iterable objects. An iterator is an object which implements the iterator protocol, which consist of the methods __iter__() and __next__(). WHAT…

  • 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?

    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?

    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?

    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?

    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…