Skip to Main Content

Introduction to Python

This guide was designed to supplement the INTRODUCTION TO PYTHON virtual workshop. If you have concerns or suggestions for this guide, feel free to reach out to scholarlyengagement@tulane.edu.

What are functions?

Functions are groups of statements that perform a specific task on your data. Functions typically take the following structure:

Function(argument1, argument2.....argumentx)

In this section, you will learn how to:

  • Use common functions such as print () 

Common Functions

Copy the following code on the left in your IDE to execute the process shown in the image on the right.


Revealing the Content of a Variable  |  print(argument)

We have used print a couple of times in this guide. Print is one of the most frequently used functions.

name1 ="Raquel"                                                                      
print (name1)

 

 

 


Finding the Highest Number in a List | max(list)

list3 = [1, 17, 25]                                                                  
print (max(list3))

 

 

 


Finding the Lowest Number in a Listmin(list)

list3 = [1, 17, 25]                                                                                           
print(min(list3))

 

 


Finding the Last Word in Alphabetical Order | max(list)

names = ("Xay","Sheila", "Rhonda", "Jay", "Bob")                           
print(max(names))                                 

 

 

 


Finding the First Word in Alphabetical Order | min(list)

names = ("Xay","Sheila", "Rhonda", "Jay", "Bob")
print(min(names))                               

 

 

 


Alphabetically Sorting a List of Strings | type(variable)

names = ("Xay","Sheila", "Rhonda", "Jay", "Bob")
print(sorted(names))                    

 

 

 


View Object Type | type(variable)

name = "Jason"                                 
print(type(name))

 

 


Absolute Value | abs(number)

print(abs(-99))                                                                                                  

 

 

 


Power Function | pow(base, exponent)

print(pow(7,2))                                                                                                    

 

 


Rounding | round(number, decimal places)

print(round(14.9234))
print(round (14.9234, 2))                                                        
print(round (14.9234, 3))                         

 

 

 

 


Finding the Length of a String Variable | len(string)             

name = "Sheila"                                                                                         
print(len(name))                                                  

 

 

 


Finding the Length of a List | len(list)

cars = ["Toyota", "Honda"]                                                             
print(len(cars)) 

 

 

 


Adding Numbers | sum(list of numbers)

summ = sum([1,5,6,7])                                             
print(summ)

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.