10 Basic python built-in functions


Posted on August 31, 2018 by Aisah in Coding journey,Techie stuff

10 basic built-in python functions

So i kinda want to publish posts here where, i kind of show bits and pieces of my coding journey. I started with python a while back and i thought in would be usefull to do a small summary of 10 built in functions. They are usually the first ones you encounter when learning python.

In this post i name the function,  I show a little example and what the result is supposed to be. At the end of the post i summarized these functions in an image. Feel free to share the image and tell me where you are in your coding journey.

—————————————————————————————————————————————–

1. print()

This function shows the string-value of the object you put inside the parentheses on the screen

print('Hello World')

Result

2. input()

This function waits for the user to type some text on the keyboard and press ENTER.

Name = input("Please enter your name")
print('Hi ' + Name + ' Thank you for entering your name')

—————————————————————————————————————————————–

3. len()

This function returns the length of the object passed. Show the no of characters of a string

x = len('Hello')
print("How many letters are in the word hello?")
print(x)

—————————————————————————————————————————————–

4. range()

returns sequence of integers between start and stop. Frequently used in for loops

for i in range(4):
    print(i)

print('--------')

list_of_things_i_like_to_eat = ['Chocolate', 'Cookies', 'Cakes']
for j in range(len(list_of_things_i_like_to_eat)):
    print(list_of_things_i_like_to_eat[j])

Result

—————————————————————————————————————————————

5. str()

Evaluates to the string value of the object you pass

word = input("please type in a word and we will count the number of characters")
count = len(word)
print("The number of characters in " +word+ " is: "+str(count))

—————————————————————————————————————————————–

6. int()

eturns the integer value of the string you pass

a = input("Please type a whole number between 0-10")
b = input("Please type aother whole number between 0-10")
c =  int(a) + int(b)
print("The sum of the numbers you typed is " + str(c))

Result

—————————————————————————————————————————————–

7. chr()

Return the string representing a character whose Unicode code point is the integer i.

print(chr(97))
print(chr(98))
print(chr(99))
print(chr(100))

Result

—————————————————————————————————————————————–

8. sum()

Returns the total of the items of an iterable. For example a list.

list = [1,2,3,4]
a = sum(list)
print(a)

Result

—————————————————————————————————————————————–

9. pow()

Returns x to the power y.

print('Hello World')
Hello World

Result

—————————————————————————————————————————————–

10. max()

returns largest element

list = [1,2,3,4,6,9,7,32,5]
a = max(list)
print(a)

Result

—————————————————————————————————————————————–

10 python functions
Author

Eve

A fellow-traveler of life figuring out the way. I like to share little nuggets of wisdom i found on this journey. blogger coder baker mom of 2


Comments


  • Dit is echt techie stuff. Mijn kennis van techie is hoe werkt mijn telefoon, laptop en basic words/excel. De rest laat ik over aan jou, ter en vince

  • Write a Reply or Comment

    Your email address will not be published. Required fields are marked *


    *