Python question

How do you write comments in python?

less than 1 minute read

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...

What is PYTHONPATH?

less than 1 minute read

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 ...

What are python modules?

1 minute read

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...

What is namespace in Python?

2 minute read

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...

How to create an empty class in Python?

less than 1 minute read

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...

What does an object() do?

less than 1 minute read

The object() function returns an empty object. You cannot add new properties or methods to this object. This object is the base f...

Does python make use of access specifiers?

1 minute read

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...

What is encapsulation in Python

less than 1 minute read

Encapsulation - Restrict the access to methods or variables. This can prevent the data from being modified or accessing accidentally, but not intentionally. ...

How do you do data abstraction in Python?

less than 1 minute read

Data Abstraction is providing only the required details and hiding the implementation from the world. It can be achieved in Python by using interface...

Does python support multiple inheritance?

less than 1 minute read

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...

What is monkey patching in Python?

less than 1 minute read

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...

What is Polymorphism in Python?

less than 1 minute read

Polymorphism - The word means having many forms. In programming, polymorphism means same function name (but different signatures) being uses for different t...

How are classes created in Python?

less than 1 minute read

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...

How is Multithreading achieved in Python?

less than 1 minute read

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...

What is pep 8?

less than 1 minute read

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...

Does Python have OOP’s concepts?

less than 1 minute read

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...

How to remove values to a python array?

less than 1 minute read

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...

How to add values to a python array?

less than 1 minute read

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...

What are the built-in types of python?

less than 1 minute read

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...

What are Python packages?

less than 1 minute read

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 ...

How can files be deleted in Python?

less than 1 minute read

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...

What mean Inheritance

less than 1 minute read

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...

What does len() do?

less than 1 minute read

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...

What are docstrings in Python?

less than 1 minute read

Python documentation strings (or docstrings). It is used like a comment, to document a specific segment of code. The docstring should descr...

How to comment multiple lines in python?

less than 1 minute read

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...

What is type conversion in Python?

2 minute read

It convert one data type to another. Additional information There are two types of Type Conversion in Python: Implicit Type Conversion - The Python int...

What are the generators in python?

less than 1 minute read

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...

What is self in Python?

less than 1 minute read

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 ...

What is split used for?

less than 1 minute read

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:...

What are Python libraries?

less than 1 minute read

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...

What is pickling and unpickling?

1 minute read

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...

What is a lambda function?

1 minute read

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 ...

What are the key features of Python?

1 minute read

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...

What are python iterators?

less than 1 minute read

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...

What is init?

less than 1 minute read

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...

Is indentation required in python?

1 minute read

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 ...

What are functions in Python?

less than 1 minute read

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...

Is python case sensitive?

less than 1 minute read

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...

How is memory managed in Python?

2 minute read

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...

What does [::-1] do?

less than 1 minute read

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...

How to import modules in python?

less than 1 minute read

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: ...

Back to Top ↑

Python exercise

What means list [-1]?

less than 1 minute read

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 ...

Which one of these is floor division?

less than 1 minute read

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...

How to produce a star triangle?

1 minute read

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...

How to check if a sequence is a Palindrome?

less than 1 minute read

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...

How to check if a number is prime?

1 minute read

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...

What is a Bubble sort algorithm?

less than 1 minute read

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...

Back to Top ↑

Python

Strings

1 minute read

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...

For loop

3 minute read

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.

Boolean Values

1 minute read

Is a data type that has one of two possible values (usually denoted true and false).

Python Try Except

2 minute read

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...

Tuple

1 minute read

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.

Sets

3 minute read

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...

Statements

2 minute read

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...

While Loops

2 minute read

With the while loop we can execute a set of statements as long as a condition is true.

Dictionary

4 minute read

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...

Python Numbers

2 minute read

There are three numeric types in Python. Variables of numeric types are created when you assign a value to them.

Back to Top ↑

Visual studio code

Back to Top ↑

Python project

Mad libs

2 minute read

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...

Back to Top ↑