python pt.1

Python

reference python link

Definition of Python

  • It is used for various purpose: data analysis, program engineering
  • interpreter language (compatible computing language)
  • easier to learn than other languages

Types of variables

  1. int(integer)
  2. float
  3. bool(True/False)
  4. str(string-characters)

Operators

  • The normal operation (calculation) is possible to not only numbers but also strings.
  • example:
    1
    2
    print('Hello!' *3)
    # The result: Hello!Hello!Hello!
  • Logical operators and comparative operators are also possible in python.

Data structures: 4 types

  1. List
  • format: [] (separation with ‘,’(comma))
  • indexing with slicing (This is the most important thing!!! in data analysis): python indexing
  • .append(): add the data in the list
  • .sort() or .sort(reverse=True): sorting the data by the ascending or descending order
  • .reverse: printing data by the reverse order of the list data
  1. Dictionary
  • format: {keys:values}
  • values in dictionary type: list type, set type, strings, int/float
  • print the values using the indexing
  • update or .append(): add or change the data
  1. Tuple
  • format: () (separation with ‘,’(comma))
  • The data is fixed, so changing the data is impossible.
  • Adding the data is possible.
  1. Set
  • format: {} (similar to dictonary but no keys and values)
  • remove the duplication (the unique data): if you add the same data a lot, the only one data is added into the data set.
  • the operation: intersection, union, difference