Skip to main content

Built in function in Python with example

 Python provides a rich set of built-in functions that are readily available for use without requiring any import statements. These functions are part of the Python Standard Library and cover various aspects of programming. Let's look at some common built-in functions with examples:

1. `len()` - Returns the number of items in an object:

```python
fruits = ["apple", "banana", "orange", "grape"]
print(len(fruits))  # Output: 4

text = "Hello, World!"
print(len(text))  # Output: 13
```

2. `print()` - Prints the specified message to the console:

```python
print("Hello, World!")  # Output: Hello, World!
```

3. `range()` - Generates a sequence of numbers:

```python
# Generate numbers from 0 to 9
numbers = list(range(10))
print(numbers)  # Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

# Generate numbers from 5 to 14 (exclusive)
numbers = list(range(5, 15))
print(numbers)  # Output: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

# Generate even numbers from 0 to 10
even_numbers = list(range(0, 11, 2))
print(even_numbers)  # Output: [0, 2, 4, 6, 8, 10]
```

4. `input()` - Reads user input from the console:

```python
name = input("Enter your name: ")
print("Hello,", name)
```

5. `type()` - Returns the type of an object:

```python
number = 42
print(type(number))  # Output: <class 'int'>

fruits = ["apple", "banana", "orange"]
print(type(fruits))  # Output: <class 'list'>
```

6. `int()`, `float()`, `str()` - Convert data types:

```python
x = "10"
y = int(x)
print(y)  # Output: 10

z = float(y)
print(z)  # Output: 10.0

text = str(z)
print(text)  # Output: '10.0'
```

7. `sum()` - Returns the sum of elements in an iterable:

```python
numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
print(total)  # Output: 15
```

These are just a few examples of the many built-in functions available in Python. The Python Standard Library offers a wide range of built-in functions to handle strings, numbers, lists, dictionaries, files, and more, making Python a powerful and convenient language for various programming tasks.

Comments

Popular posts from this blog

Gujarati Keyboard layout (terafont-varun), Computer Short cut key, Tally short cut key

Word , Excel , Power Point Shortcut Key in Gujarati

Terafont-Varun (Gujarati Typing) Keyboard Layout by "Sama Soyab"

  For Gujarati Typing : Required : Terafont-Varun Font  After Successfully Installed Terafont Varun Open Any Text Editor or any program. Select Font Terafont-Varun -> Ok For more detail please watch below video. Search Topics : Learn terafont varun, Learn terafont chandan, Learn terafont gujarati to english translation, Learn terafont varun keyboard, Learn terafont converter, Learn terafont varun zip, Learn terafont keyboard, Learn terafont kinnari, Learn terafont akash, Learn terafont aakash, Learn terafont akash ttf, Learn terafont aakash gujarati download, Learn terafont akash keyboard, Learn terafont akash download for windows 10, Learn terafont akash font download, Learn terafont arun, Learn terafont border, Learn terafont chandan keyboard, Learn terafont-chandan font, Learn tera font chandana, Learn convert terafont to shruti, Learn convert terafont varun to shruti, Learn terafont varun chart, Learn terafont download, Learn terafont download for windows 10, Learn tera...