
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10478 Articles for Python

23K+ Views
To set the PYTHONPATH environment variable on Linux, follow these steps − Open a terminal window on your Linux system. Determine the path to your Python module or package. For example, suppose you have a Python module named mymodule located in the /home/user/myproject folder. Set the PYTHONPATH environment variable to the path of your module or package using the following command − $export PYTHONPATH=/home/user/myproject:$ This command sets the PYTHONPATH environment variable to /home/user/myproject and also includes the previous value of PYTHONPATH in case it was already set. Note that the path should be separated by a colon (:) on Linux. Verify that the PYTHONPATH environment variable has been set correctly using the following command − ... Read More

43K+ Views
In Python, PYTHONPATH is an environment variable that specifies a list of directories to search for Python modules when importing them. When you import a module in Python, Python looks for the module in the directories specified in sys.path, which is a list of directories that includes the current working directory and directories specified in PYTHONPATH. PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find ... Read More

2K+ Views
The "from module import *" statement is used to import all function from a Python module. For example, if you want to import all functions from math module and do not want to prefix "math." while calling them, you can do it as follows:>>> from math import * >>> sin(0) 0.0 >>> cos(0) 1.0Note that for any reasonable large set of code, if you import * you will likely be cementing it into the module, unable to be removed. This is because it is difficult to determine what items used in the code are coming from 'module', making it easy ... Read More

2K+ Views
The "from module import function" statement is used to import a specific function from a Python module. For example, if you want to import the sin function from the math library without importing any other function, you can do it as follows:>>> from math import sin >>> sin(0) 0.0Note that you don't have to prefix sin with "math." as only sin has been imported and not math. Also you can alias imported functions. For example,>>> from math import cos as cosine >>> cosine(0) 1.0

9K+ Views
Importing modules is an essential part of programming in Python, and it's something you'll do a lot as you develop your skills. In Python, you can import multiple modules using a few different methods. Here are some examples of how to do it: Import each module on a separate line The simplest way to import multiple modules in Python is to import each one on a separate line. For example, suppose you want to import the math, random, and time modules. You could do it like this: Example This code tells Python to import the math, random, and time modules ... Read More

8K+ Views
In Python, you can use the import statement to use functions or variables defined in another module. Here are some code examples that demonstrate how to use multiple modules with Python import statement: Suppose you have two modules module1.py and module2.py that contain some functions: Example #module1.py def say_hello(name): print("Hello, " + name + "!") #module2.py def say_goodbye(name): print("Goodbye, " + name + "!") To use these modules in another Python program, you can import them using the import statement: import module1 import module2 module1.say_hello("John") module2.say_goodbye("Jane") ... Read More

2K+ Views
The import statement in Python is used to bring code from external modules or libraries into your program. This is a powerful feature that allows you to reuse code and avoid duplicating code across multiple programs. Here are some examples of how to use the import statement: Import a single module Let's say you want to use the math module in your program, which provides a variety of mathematical functions. To import the math module, you simply use the import statement followed by the name of the module: Example In this example, we import the math module and use the ... Read More

2K+ Views
In Python, both modules and packages are used to organize and structure code, but they serve slightly different purposes. A Python module is a single file containing Python code that can be imported and used in other Python code. A module can define variables, functions, classes, and other Python constructs that can be used by other code. Modules are a great way to organize code and make it reusable across multiple programs. A Python package, on the other hand, is a collection of related Python modules that are organized in a directory hierarchy. A package can contain one or more ... Read More

185 Views
The zfill() method in Python is used to pad a string with leading zeros to achieve a specified total length. If the string is already longer than the specified length, zfill() does nothing. Syntax Following is the syntax for the zfill() method string.zfill(width) Consistent File Naming Consistent file naming with leading zeros is crucial for sequential processing scripts because it ensures correct sorting and handling of files. Example Here, even though i ranges from 1 to 10, each number is formatted to have three digits with leading zeros, ensuring consistent filename length. for i in range(1, 11): ... Read More

12K+ Views
In Python, there are several methods to check if a given character in a string is an alphabetic letter. Here, we'll explore three effective techniques: using the isalpha() method, the string module, and regular expressions. Using the isalpha() method The isalpha() method is a built-in method in Python that returns True if all the characters in a string are alphabets (letters) and False otherwise. Example In this example, we have a string "Hello World" and we want to check if the character at index 1 is a letter. We use the isalpha() method to check if the character is ... Read More