How do you write comments in python?
A single line comment can be added by using the hash (#)character. The hash (#) is added for every line that should be commented. Example: #This is a comme...
A single line comment can be added by using the hash (#)character. The hash (#) is added for every line that should be commented. Example: #This is a comme...
A) They are used to indicate a private variables of a class. B) They confuse the interpreter. C) They are used to indicate global variables. D) They slow ...
It is an environment variable which is used when a module is imported (allow users to import modules that have not been installed yet), you can configure to ...
A Python module is a .py file containing executable code or a set of functions you want to include in your application. In short words It is a Python file co...
Namespaces make our programs immune from name conflicts A namespace is basically a system to make sure that all the names in a program are unique and can...
To write an empty class we use the pass statement, it is a special statement in Python that does nothing. It only works as a dummy statement. Objects of an e...
The object() function returns an empty object. You cannot add new properties or methods to this object. This object is the base f...
Yes, access specifiers or access modifiers in python programming are used to limit the access of class variables and class methods outside of class while imp...
Encapsulation - Restrict the access to methods or variables. This can prevent the data from being modified or accessing accidentally, but not intentionally. ...
Data Abstraction is providing only the required details and hiding the implementation from the world. It can be achieved in Python by using interface...
Yes, Python supports multiple inheritance. A class can be derived from more than one base class, this is called multiple inheritance. The features of all t...
It is a dynamic (run-time) technique in Python by which you can modify the behavior of an existing class or module. In short words refers to dynamic modific...
Polymorphism - The word means having many forms. In programming, polymorphism means same function name (but different signatures) being uses for different t...
Python is an object oriented programming language. Almost everything is an object, with its properties and methods. A Class is like an object constructor, or...
Python has a construct called the Global Interpreter Lock (GIL). The GIL makes sure that only one of your threads can execute at any one time. A thre...
Interpreted vs compiled language An interpreter executes the statements of code “one-by-one” while the compiler executes the code entirely and lists all pos...
The PEP is an abbreviation form of Python Enterprise Proposal. PEP 8 is a document that provides various guidelines to write the readable in Python. PEP 8 de...
LIST Type - Are mutable (can be edited), it is possible update or delete an item from the list. Iteration - It is slower than tuples. Syntax - You use squ...
Shallow copies It duplicate as little as possible. A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow ...
Yes, like other general purpose programming languages(Java, C++. C#, Ruby), Python is also an object-oriented language. It allows us to design programs using...
Array elements (list) can be removed using pop() or remove() method. The difference between these two functions is that the first one returns the deleted val...
Append Syntax - list.insert(element). With this method, you can add a single element to the end of a list. Example - Append a integer: numbers = [1, 2, 3...
NumPy is a Python extension module and fundamental package for scientific computing . The arrays facilitate advanced mathematical and other types of operatio...
Global variable It is defined and declared outside a function and we need to use them inside a function. These variables can be accessed by any function in ...
Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these c...
It is a container where you can save one o more relevant modules to organize. To create a package, you create a new folder and place the relevant modules in ...
To delete a file, you must import the os module, and run the os.remove() function: import os os.remove("practice.py") After this you will see next to the...
Python programming language supports negative indexing of arrays(list), something which is not available in arrays in most other programming languages. This...
Inheritance is the capability of one class to derive or inherit the properties from another class. It provides code reusability, makes it easier to create an...
It is used to determine the length of a string, list, array and etc, this mean that returns the number of items in an object. Example-1: When the object is...
Putting *args and/or **kwargs as the last items in your function definition’s argument list allows that function to accept an arbitrary number of arguments a...
Also known as conditional expressions. It is used to return a value based on the result of a binary condition. It takes binary value(condition) as an input, ...
Regular expression A Regular Expression or (RegEX) is a stream of characters that forms a pattern. Whether a string contains this pattern or not can be dete...
Python modules are not always de-allocated when Python exits. Explanation: The modules with circular references to other objects, or to objects ref...
Operators are special functions. They take one or more values and produce a corresponding result. is - It is used to check if two values (or variables) are ...
help() function - It is used to display the documentation string and also facilitates you to see the help related to modules, keywords, attributes, etc. Exa...
Python documentation strings (or docstrings). It is used like a comment, to document a specific segment of code. The docstring should descr...
Python does not really have a syntax for multi line comments. To add a multiline comment you could insert a # for each line. Example: #This is a comment #w...
After this question probably you are wondering what is the difference between programming and scripting language?. The only difference which exists is that t...
Capitalize() Convert the first letter in the string in a capital letter. Syntax - string.capitalize(). Example: txt = "hello!" x = ...
It convert one data type to another. Additional information There are two types of Type Conversion in Python: Implicit Type Conversion - The Python int...
It is Functions that return iterable items to do it use the yield keyword instead than return. If the body of a def function contains yield, the function aut...
The self parameter is a reference to the current instance of the class, is always pointing to current Object and is used to access variables that belongs to ...
The principal difference is that range returns a Python list object and xrange returns an xrange object. This means that xrange doesn’t actually generate a ...
The random module provides a shuffle() function that returns a sequence with its elements randomly. Example: import random numbers = [1, 2, 3, 4, 5, 6,] ra...
Random module is the standard module that is used to generate a random numbers. The function random.random() is a absolute basic random number gener...
This method separate a string into a list. You can specify the separator, when this isn’t defined, whitespace(” “) is used. Example - Separator not defined:...
It is a collection of files (known as Modules) that contains functions for use by other programs. Libraries allows you to perform lots of actions without wri...
The compiling and linking allows the new extensions to be compiled properly without any error and the linking can be done only when it passes the compiled pr...
Pickling It is a process of converting a object into a bytes stream and it is bstored into a file. Unpickling It is inverse operation of pickling. Unpick...
There are mainly two types of functions: Normal function - It is is defined by the keyword def and it has a name. Example: my_func is de name and we ...
Python is an interpreted language. That means that is a simple language, it does not need to be compiled before it is run. You don’t need t...
An iterable is any object that can return an iterator and an iterator is the object used to iterate over an iterable object. This implement...
All classes have a function called init(), is always executed when class is initiated. The method is useful to do any initialization you want to do with you...
Install python After that, install it on your PC. Look for the location where PYTHON has been installed using the following command on your command prom...
Yes, it is necessary because specifies a block of code. It is a way of telling a Python interpreter that a group of statements belongs to a particular block ...
A function is a block of code which only run when it is called. A function can return data as a result. To define a Python function, the def keyword i...
Yes. Python is a case sensitive language. Example, if a variable is named ‘HelloWorld‘, then an error will occur if the variable is called ‘helloworld‘. Vari...
Break - It finish the current loop. Use the break statement to come out of the loop instantly. Continue - Skip the current iteration of a l...
Memory management in python is managed by Python private space. All objects and data structures are located in a private place. The programmer does n...
They are similar because an array is also a data structure that stores a collection of items. Like lists, arrays are ordered, mutable, enclosed in square bra...
It means that for a given string/list/tuple, you can slice the said object using the format: <object_name>[<start_index>, <stop_index>, &l...
Python modules can get access to code from another module by importing the file/function using the keyword import. You can do it in different ways: ...
To convert String to lowercase, you can use lower()v function on the String. String.lower() function returns a string with all the characters of thi...
Suppose: list = [2, 33, 222, 14, 25] print(list[-1]) Options: A) Error B) None C) 25 D) 2 Answer: C) 25. The index -1 corresponds to the last index ...
A) numbers = 1,000,000 B) numbers = 1000 2000 3000 C) numbers = 1000, 2000, 3000 D) numbers = 1,000,000 Answer: B) numbers = 1000 2000 3000 Whitespace i...
A) 31 characters. B) 63 characters. C) 79 characters. D) None of the above. Answer: “D”. None of the above because identifiers are unlimited in length. ...
A) / B) // C) % D) None of the mentioned. Answer: B) // You use floor division operator // or the floor() function of the math module to get the floor d...
The Python language, like many other high-level programming languages, offers the ability to sort data out of the box using sort(). You can use to sort any l...
Your code should work even if the file is too big to fit in memory. ______ We need to write a multiple line solution and then convert it to one liner code. ...
The primary purpose of creating this program is to explain the concept of the loop in the Python program in a simple example. Example - Display stars in equ...
A string is said to be palindrome if the reverse of the string is the same string. Example: Input: level Output: Yes Input: civic Output: Yes Input: Elli...
What is Fibonacci Series? - It is a series of numbers formed by the sum of the two preceding numbers in the series. 0,1,1,2,3,5 The 1 is found by...
number = int(input("Write a number: ") # If given number is greater than 1 if number > 1: # Iterate from 2 to n / 2 for e in range(2, int(nu...
Bubble sort The basic idea is that a given list or sequence of data is verified for the order of neighboring elements by comparing them with each other. Ele...
Strings can be created by enclosing characters inside a single quote or double-quotes and the output will be the same. They are immutable, you can’t modify t...
With this function we can execute a set of statements. It is used when you need to check in a condition each iteration, or to repeat a block of code.
Is a data type that has one of two possible values (usually denoted true and false).
Exceptions in Python applications can happen for many of reasons; and if they aren’t handled well, these exceptions can cause the program to crash or causing...
Tuples are used to store multiple items in a single variable, is a collection which is ordered and unchangeable and are written with round brackets.
the collection is mutable and the elements can be added and removed to the set. The set are very similar to the dictionaries, limited by curly b...
Conditional statements allow you to control the flow of your program more effectively. The statements “In, if and else” evaluate when an expression is true o...
With the while loop we can execute a set of statements as long as a condition is true.
It’s a fundamental data structure in python, are mutable and we can always add new items after the dictionary has been created. The dict() func...
Reserved Words
There are three numeric types in Python. Variables of numeric types are created when you assign a value to them.
From the File Explorer toolbar, select the New File button or ctrl n. Name the file how you prefer “title.py”. By using the .py file extension, you tell visu...
According to Wikipedia, “Mad Libs is a phrasal template word game where one player prompts others for a list of words to substitute for blanks in a story bef...