<jupyter_start><jupyter_text>Data types & Structures  A great advatage of `Python` is the type of data it can handle & combinePython has been widely used to handle internet related operations, which means lots and lots of text and numbers. combined! ***  Let's start with the basic types! Like other programing languages, `Python` data types include integers, floats, complex, and strings & boolean     Try it out!    In the next cell, assign a float value to x and execute the cell<jupyter_code>lat = 20
print(lat)<jupyter_output><empty_output><jupyter_text>Try it out!    Assign an integer value to y and execute the cell<jupyter_code>y = 
print(y, lat*y)<jupyter_output><empty_output><jupyter_text>Complex values are identified by a `j` at the end    Try it out!    Assign a complex value to z and execute the cell<jupyter_code>z = 
print(z, type(z))<jupyter_output><empty_output><jupyter_text>Variables can be reassigned to other types anytime    Try it out!    Execute the next cell<jupyter_code>lat = 'Latitude'  
print(lat)
step = True
print(step)<jupyter_output><empty_output><jupyter_text>Try it out!    Define your own string and boolean variables and print their type in the next cell  One of the best types: datetime!    Try it out!    - Execute the code in the next cell to define two datetime variables: today1 & today2<jupyter_code>from datetime import date # call date function inside the datetime package
today1 = date.today()
from datetime import datetime # call datetime function inside the datetime package
today2 = datetime.now()<jupyter_output><empty_output><jupyter_text>Try it out!     - Now print both variables        - Try printing today1.month        - Try printing the following today2.strftime('%c')        - Now print the type of one of your date variables  Note the use of . after a variable. This refers to a method of the variable or, as Python refers to it, the object. We will use other functions of the datetime package later, and you could find more details about the attributes of the datetime object (variable): https://www.guru99.com/date-time-and-datetime-classes-in-python.html***  Python has a some basic data collections, we will talk about three of them:    List - ordered, changeable, allows duplicates    Tuple - ordered, unchangeable, allows duplicates    Dictionary - unordered, changeable, no duplicates allowed***  Lists: ordered, changeable, allows dupplicates    Try it out!    - Execute the code below and print the list        - Print the type of mylist<jupyter_code>mylist=['temperature', 'wind', 'salinity']  # note the use of [ ]<jupyter_output><empty_output><jupyter_text>To access an element of a list we use the indices, that start at `0`    Try it out!    - Try printing: mylist[0]        - Now try reassigning the value of the second value to 'current velocity'  To add an element to the list use the method append    Try it out!    - Try mylist.append('wind speed')        - Then execute the next cell to print the entire list with a for loop<jupyter_code>for myvar in mylist:
    print(myvar+" has been recorded")<jupyter_output><empty_output><jupyter_text>Copying a list (or another object) needs to be done explicitely, other wise is just a new name for your variable    Try it out!    - Try these two codes:              yourlist1 = mylist.copy()              yourlist2 = mylist        - Then modify yourlist1 and print it along with mylist        - Now modify yourlist2 and print it along with mylist *** Tuples: ordered, unchangeable, allows duplicates    Try it out!    - Execute the code below and print the tuple        - Print the type of mytuple        - Print one element of mytuple<jupyter_code>mytuple = ('latitude', 'longitude', 'time')  # note the use of ( )<jupyter_output><empty_output><jupyter_text>Try it out!     - Now try reassigning an element of mytuple ***  Dictionaries: unordered, changeable, no duplicates allowed Indexed pair of keys and values    Try it out!    - Execute the code below, and print the dictionary        - Add a new element to mydict with mydict['units']='C'        - Print one element of mydict. Hint: the key is the key<jupyter_code>mydict = {'instrument': 'temperature sensor', 'measurement':'SST','depth': 5}<jupyter_output><empty_output><jupyter_text>Certain libraries have specific data structures - arrays, data frames, and datasetsexamples of each, but we will go back talking about each library. ****** Few words about `Objects`, `Attributes` & `Methods` `Python` is an object oriented programming language. This means almost everything is an object or instances of a class. Variables are objects. And therefore they have `attributes` & `methods` `Properties` or `Attributes` are accessed with  `.attribute` after the object `Methods` are functions, & are accessed with `.method(arguments)` after the objectWe're not going to teach you how to create classes with properties or methods, but how to access them, because we will use them extensively    Try it out!    Execute the code in the next cell to access the attributes and one method of the class date<jupyter_code>today = date.today()
print(today)
## Date object attributes
print(today.year, today.month, today.day) 
## Date object method 'ctime' - do not need arguments
print(today.ctime())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07438172550500283, 'fraction_numerical': 0.003209363790824995, 'mean_word_length': 4.240356083086054, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '11453', 'license': 'Apache-2.0', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1423, 'n_words': 673, 'path': 'notebooks/Tutorial_04_DataTypesStructures.ipynb', 'repo_name': 'python4oceanography/ocean_python_tutorial', 'size': '5297'}