# from keyword with example in Python

**Python from keyword**: Here, we are going to learn about the **from keyword with example**.

Submitted by **IncludeHelp**, on April 16, 2019

## Python from keyword

**from** is a keyword (case-sensitive) in python, it is used to import a specific section from a module, like functions, classes, etc.

**Syntax of from keyword**

from module_name import specific_section1, specific_section1, ...

Here, specific_section(s) are the names of functions, classes, etc.

**Example:**

# importing factorial from math module from math import factorial

### Python examples of from keyword

**Example 1:** Find factorial of a number by importing factorial from math module.

# python code to demonstrate example of # from keyword # Find factorial of a number # by importing factorial from math module. # importing factorial from math module from math import factorial num = 4 # printing factorial print("factorial of ", num, " is = ", factorial(num))

**Output**

factorial of 4 is = 24

**Example 2:** Find factorial and square root of a number by importing two functions factorial and sqrt from math module.

# python code to demonstrate example of # from keyword # Find factorial and square root of a number # by importing two functions factorial and sqrt # from math module. # importing factorial and sqrt from math module from math import factorial, sqrt num = 4 # printing factorial & square root print("factorial of ", num, " is = ", factorial(num)) print("square root of ", num, " is = ", sqrt(num))

**Output**

factorial of 4 is = 24 square root of 4 is = 2.0

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.