---
# System prepended metadata

title: Lesson 1

---

# Lesson 1

## How to install a Python environment

In macOS: `brew install python` in terminal. Then we can execute `python3` command to get a running instance.

## What is a source code

Source code is a **text file** which can be compiled by a programming language specified compiler. For example, Python's source code is a file with `.py` extension.

## The first Python program - Hello world

```python
print('Hello World')
```

1. Global method: `print(argument)`.
2. Types: string.
3. Variable and constants.

# Lesson 2

## What is a variable

Variable is a name for some instance of a type. It could be reassigned to a new value (editable). And can be called by its name (call by name).

```python
name = 'Yufan'
new_name = name

name = 'Wenjing'

print(name)
print(new_name)
```

## The naming formats for a variable

A variable should start with letter of underscore, then you can use any letters, numbers or underscore.
For example, `_name_` is a valid variable, but `1_name` couldn't be treated as a variable.

1. Camelcase: start with a lower-case letter, the continue words should start with a upper-case letter. For example: `smallCharactor`, `litterAnimals`.
2. Underscore: every words should use lower-case letter, use underscore link the words. For example: `litter_dog`, `lovely_house`, `welcome_message`.
3. PascalCase: The first letter should be upper-case when compare with the camelcase. For example: `BigBrother`, `SetUp`.

## How to measure the binary data

1. Only one zero or one is a **bit**.
2. Eight bit would be called as a **byte**.
3. `2 ** 10` byte would be named as **KB**.
4. `2 ** 10` KB would be named as **MB**.
5. `2 ** 10` MB would be named as **GB**.
6. `2 ** 10` GB would be named as **TB**.
7. `2 ** 10` TB would be named as **PB**.

The bandwidth of a network, for example 1000M is 1000Mb, which means 1000M bit. It's equal to 125 MB.

## The encoding of a character

ASCII is a one byte encoding, which can present 256 characters. Including lower-case letters, upper-case letters, numbers and some symbols (.,/\?;:'"[]{}+-=-()`~\n\r\t). a is 47.

GB2312 is the encoding format for Chinese. Microsoft extends the GBK based on the GB2312, which can present more Traditional Chinese words.

JIS is the encoding format for Japanese.

The uniform character encoding format for all the languages around the world is called Unicode. Which can have multi-formats. Such as UTF-8, UTF-16, UTF-32. Python 3 is based on UTF-8.
Unicode is a dynamic length encoding.

## string is chain of character

The string is not the basic data type for Python. It's an array of character which can be wrapped in a pair of quotes. You can used it as a basic data type.

## How to operate a string

### Change the case of the letters in a string

1. `'some string'.title()`
2. `'some string'.upper()`
3. `'SOME STRING'.lower()`

### Inline a variable in a string

We should start with a special letter `f`, then continue with a string. The variable in this string should be wrapped with a pair of brace.

```python
name = 'Yufan'
welcome_message = f'Welcome {name}. Today is a nice day.'
print(welcome_message)
# print(f'Welcome {name}. Today is a nice day.')
```

### The method call in python.

The format should be `variable . method_name ( arguments... )`

### How to format a string.

`'some string'.format( arguments )`, the arguments should be inlined by `{index}`.

For example, `'Welcome {0}'.format('Yufan')`, `'{0} is the husband of {1}'.format('Yufan', 'Wenjing')`

### The escapes in a string.

1. `'\n'`
2. `'\t'`
3. `'\\'`
4. `'\'' => "'"`
5. `"\"" => '"'`