HowTos
Free Video Tutorials
Written Tutorials
💲Paid Courses
Python Shell
Mailing List
About Us
Home/
Top Python How-To Questions
Choose the best string formatting: % vs. .format vs. f-string literal.
'.format'
string formatting
f-string
'%'
Create a dictionary with list comprehension.
python
dictionary
list comprehension
Convert two lists into a dictionary.
python
convert
list-to-dictonary
Convert an integer into a string.
python
convert
integer-to-string
Print to stderr in Python.
python
stderr
printing
zen-of-python
Use a pythonic way to create a long multi-line string.
python
string
multilinestring
multiline
Measure elapsed time in Python.
python
time
measure
Pad zeroes to a string.
python
string
pad zeros
Delete an element from a dictionary.
python
dictionary
delete element
Count the occurrences of an item in a list.
python
list
count
Remove an element from a list by index.
python
list
indexing
Determine the type of an object.
python
list
types
tuple
str
dict
int
Limit floats to two decimal points.
python
floating-point
rounding
precision
Select an item from a list randomly.
python
list
random
Read a file line-by-line into a list.
python
string
file
readlines
Call a function of a module by using its name.
python
object
function-call
Get the number of elements in a list.
python
list
len
count
Sort a list of dictionaries by a value of the dictionary.
python
list
dictionary
sorting
data-structures
Remove a key from dictionary.
python
dictionary
data-structures
unset
Upgrade all Python packages with pip.
python
pip
upgrade
Get the last element of a list.
python
list-indexing
Parse a string to a float or integer.
python
floating-point
type-conversion
integer
parsing
Convert a string into datetime format.
python
datetime
convert
Find current directory of a file.
python
directory
file-directory
Change the size of figures drawn with Matplotlib.
python
matplotlib
plot
graph
visualization
Manually raise an exception.
python
exception
raise
python-exception
Delete a file or folder.
python
directory
delete-file
file-io
Split a list into evenly sized parts.
python
list
split
chunks
Check if a given key already exists in a dictionary.
python
dictionary
dictionary-key
Make function decorators and chain them together.
python
python-decorators
decorator
Top Python What Questions
What is the Python 3 equivalent of “python -m SimpleHTTPServer”
python3
python -m SimpleHTTPServer
Why do Python classes inherit 'object'
python
inheritance
object-class
What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv?
python
venv
virtualenv
pipenv
What ipython
pyenv
virtualenvwrapper
pyvenv
What is the meaning of single and double underscore before an object name?
python
double-underscore
single-underscore
What's the canonical way to check a type in Python?
python
canonical
check-type
What is the proper way to declare custom exceptions in modern Python?
python
custom-exeptions
declare
What can I use as a replacement for the switch statement in Python?
python
replace
switch statement
How to add an existing venv virtual environment in PyCharm
venv
pycharm
What to do to import files from a different folder in python
python
python-import
importerror
Why is reading lines from stdin much slower in C++ than Python?
python
readlines
c++
Is there a way to run Python on Android?
python
android
android-scripting
Are static class variables possible in Python?
python
oop
class-variables
static
class
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
parameter-passing
python syntax
argument-unpacking
variadic-functions
What is __init__.py used for?
python
module
package
python-packaging
What are metaclasses in Python?
python
oop
metaclass
python-class
python-datamodel
Does Python have a ternary conditional operator?
python
operators
conditional-operator
ternary-operator
Python Classes and OOP Explained
oop
object oriented programming
classes
Should I use a for-loop or a list comprehension in Python?
python
list comprehension
comparing
for-loop
faster
What is the difference between a staticmethod and a classmethod in Python?
python
classmethod vs staticmethod
static method
instance method
class method
What does "yield" do in a Python function?
python
yield
generator
What is the best virtual environment for Python
python
virtual environment
venv
best
What is if __name__ == "__main__" in Python?
python
__main__
__name__==
Go to Top
Become a Patron
Do you like my work and would want to contribute? You can become a patron on my Patreon below!
Become a Patron