<jupyter_start><jupyter_text>Chapter 3 - Functions and Packages***You already know two such functions: `print()` and `type()`. You've also used the functions `str()`, `int()`, `bool()` and `float()` to switch between data types. These are built-in functions as well.<jupyter_code># Create variables var1 and var2
var1 = [1, 2, 3, 4]
var2 = True

# Print out type of var1
print(type(var1))

# Print out length of var1
print(len(var1))

# Convert var2 to an integer: out2
out2 = int(var2)<jupyter_output><class 'list'>
4<jupyter_text>Multiple arguments<jupyter_code># Create lists first and second
first = [11.25, 18.0, 20.0]
second = [10.75, 9.50]

# Paste together first and second: full
full = first + second

# Sort full in descending order: full_sorted
full_sorted = sorted(full, reverse = True)

# Print out full_sorted
print(full_sorted)<jupyter_output>[20.0, 18.0, 11.25, 10.75, 9.5]<jupyter_text>String Methods<jupyter_code># string to experiment with: place
place = "poolhouse"

# Use upper() on place: place_up
place_up = place.upper()

# Print out place and place_up
print(place)
print(place_up)

# Print out the number of o's in place
print(place.count('o'))<jupyter_output>poolhouse
POOLHOUSE
3<jupyter_text>List Methods`index()`, to get the index of the first element of a list that matches its input`count()`, to get the number of times an element appears in a list.<jupyter_code># Create list areas
areas = [11.25, 18.0, 20.0, 10.75, 9.50]

# Print out the index of the element 20.0
print(areas.index(20.0))

# Print out how often 9.50 appears in areas
print(areas.count(9.50))<jupyter_output>2
1<jupyter_text>List Methods (2)`append()`, that adds an element to the list it is called on`remove()`, that removes the first element of a list that matches the input`reverse()`, that reverses the order of the elements in the list it is called on.<jupyter_code># Create list areas
areas = [11.25, 18.0, 20.0, 10.75, 9.50]

# Use append twice to add poolhouse and garage size
areas.append(24.5)
areas.append(15.45)

# Print out areas
print(areas)

# Reverse the orders of the elements in areas
areas.reverse()

# Print out areas
print(areas)<jupyter_output>[11.25, 18.0, 20.0, 10.75, 9.5, 24.5, 15.45]
[15.45, 24.5, 9.5, 10.75, 20.0, 18.0, 11.25]<jupyter_text>Import package<jupyter_code># Definition of radius
r = 0.43

# Import the math package
import math

# Calculate C
C = 2*math.pi*r

# Calculate A
A = math.pi*r**2

# Build printout
print("Circumference: " + str(C))
print("Area: " + str(A))<jupyter_output>Circumference: 2.701769682087222
Area: 0.5808804816487527<jupyter_text>Selective import> `from math import pi`Calculate the distance travelled by the Moon over 12 degrees of its orbit.<jupyter_code># Definition of radius
r = 192500

# Import radians function of math package
from math import radians

# Travel distance of Moon over 12 degrees. Store in dist.
phi = radians(12)
dist = r*phi

# Print out dist
print(dist)<jupyter_output>40317.10572106901
{'fraction_non_alphanumeric': 0.1173109243697479, 'fraction_numerical': 0.07394957983193277, 'mean_word_length': 5.0, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '584127', 'license': 'MIT', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1059, 'n_words': 365, 'path': 'Introduction_to_Python/Ch3.ipynb', 'repo_name': 'SAbhaya/DataCamp-Notes-Py', 'size': '2975'}