<jupyter_start><jupyter_text>Python Fundamentals  iPython Notebook Magic Short cut keys: -  comment out a line of code = command + /-  run block of code = shift + enter-  autocomplete text = tab-  help for function = shift + tab-  view shortcut menu - esc then h  Web based viewer for ipython notebookshttp://nbviewer.ipython.org/  Write your first python program<jupyter_code>print "Hello there, I'm a Data Scientist!"<jupyter_output>Hello there, I'm a Data Scientist!<jupyter_text>Numbers in python:Numeric types: ***int, float,*** and ***bool***.<jupyter_code>type(2)
type(5.5)
type(True)
type(2+3j)
type("String")<jupyter_output><empty_output><jupyter_text>String InsertionBasic string insertions<jupyter_code>print "My name is {}".format('Craig')
name = "Sana"
print "Where in the world is {}?".format(name)
place = "CA"
print "{} is in {}".format(name,place)<jupyter_output>Sana is in CA<jupyter_text>You can insert multiple values into strings but requires labels<jupyter_code>place = "SF"
print "{0} is in {1} and the address is: {2}".format(name, place, "5th Mission")<jupyter_output>Sana is in SF and the address is: 5th Mission<jupyter_text>Try reversing order of the variables name and place.|<jupyter_code>place = "SF"
print "{1} is in {0} and the address is: {2}".format(place, name, "5th Mission")<jupyter_output>Sana is in SF and the address is: 5th Mission<jupyter_text>Basic math in pythonSome operators are pretty obvious<jupyter_code>5+5<jupyter_output><empty_output><jupyter_text>10+6<jupyter_code>10 % 3
3 * 7<jupyter_output><empty_output><jupyter_text>But some operators are less intuitive<jupyter_code>print "Hello" + " " + "World"
10 % 2 # modulo operator (i.e. reminder)
10 ** 2 # exponent
550 / 9
27/2 * 5<jupyter_output><empty_output><jupyter_text>Assign values to variables<jupyter_code>x = 10
y = 5
z = 4
type(y)
float(y)
int(y)<jupyter_output><empty_output><jupyter_text>Use math with variables<jupyter_code>x - y
y * z<jupyter_output><empty_output><jupyter_text>Try dividing x by z<jupyter_code>x / z<jupyter_output><empty_output><jupyter_text>Try dividing x by 4.0<jupyter_code>x / 4.0<jupyter_output><empty_output><jupyter_text>Functions  Syntax requires 4 things:-  prefix of 'def'-  name for function-  parentheses followed by a colon-  indented code on the next lineCreate a simple function<jupyter_code>def simplest_function():
    print "Hey, I made a function!"
simplest_function()<jupyter_output>Hey, I made a function!<jupyter_text>Call function by name<jupyter_code>simplest_function()<jupyter_output>Hey, I made a function!<jupyter_text>You can create a function that requires an input and returns a result<jupyter_code>def square(input_x):
    return input_x ** 2
square(5)
def square(x):
    x = x ** \ # add a back-slash for line continuation
    2
    print x
    return x
square(8)<jupyter_output>64<jupyter_text>Line Continuation Python recognizes that code lines that end with a comma are incomplete<jupyter_code>numbers = [1, 2, 3, 4, 
          5, 6, 7, 8 ,
          44, 55]
print numbers<jupyter_output>[1, 2, 3, 4, 5, 6, 7, 8, 44, 55]<jupyter_text>You can also use the backslash<jupyter_code>long_string = "This is a really really loooooong string"
print long_string<jupyter_output>This is a really really loooooong string<jupyter_text>Exercise: Build a Function 1. Create a function that converts Celsius to Fahrenheit.  Results should be accurate to at least one decimal point.<jupyter_code>def convert_temp(C):
    F = float(9/5) * C +32
    return F

# calling a function 
result = convert_temp(85)
result<jupyter_output><empty_output><jupyter_text>2. Update your function to return a sentence (string type) with the Celsius and Fahrenheit values inserted into the string.<jupyter_code>def convert_temp(C):
    F = float(9/5) * C +32
    return type(F)

# calling a function 
convert_temp(85)
def convert_temp(C):
    F = float(9/5) * C +32
    print "Then tempurature in degree farenheit right now is {}".format(F)
    print "Then tempurature in degree celsius right now is {}".format(C)
    return F

# calling the function    
convert_temp(85)
def convert_temp(degrees_c):
    degrees_f = (degrees_c + 9.0 / 5 + 32)
    return degrees_f

def convert_temp_message2(degrees_c):
    degrees_f = convert_temp(degrees_c) #referencing the previous function inside this
    message = "Then tempurature in degree farenheit right now is {}".format(F)
    return message

convert_temp(85)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10377991500782822, 'fraction_numerical': 0.023708342652650413, 'mean_word_length': 5.388571428571429, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 68, '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': '19', 'dir': 'jupyter-structured-clean-dedup', 'id': '178350', 'license': 'MIT', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1555, 'n_words': 472, 'path': '01 - Python Fundamentals.ipynb', 'repo_name': 'SanaNasar/Intro-to-Python', 'size': '4471'}