此篇文章是我學習Python整理的筆記,如果有任何錯誤請留訊息給我,萬分感謝。

Python intro

Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. Python combines remarkable power with very clear syntax. It has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++. It is also usable as an extension language for applications that need a programmable interface. Finally, Python is portable: it runs on many Unix variants, on the Mac, and on PCs under MS-DOS, Windows, Windows NT, and OS/2.

Python Installation https://www.anaconda.com/

With over 20 million users worldwide, the open-source Individual Edition (Distribution) is the easiest way to perform Python/R data science and machine learning on a single machine.

Python practice

Data Types

  1. Text Type: str
  2. Numeric Types: int, float, complex
  3. Sequence Types: list, tuple,range
  4. Mapping Type: dict
  5. Set Types: set, frozenset
  6. Boolean Type: bool
  7. Binary Types: bytes, bytearray, memoryview
  8. None Type: NoneType
Data type Example
str x =”Hello Eunice”
int x = 12
float x = 10.5
complex x = 2j
list x = [“dog”, “cat”, “turtle”]
tuple x = (“dog”, “cat”, “turtle”)
range x = range(6)
dict x = {“name” : “Eunice”, “age” : 18}
set x = {“dog”, “cat”, “turtle”}
frozenset x = frozenset({“dog”, “cat”, “turtle”})
bool x = True
bytes x = b”Hello”
bytearray x = bytearray(5)
memoryview x = memoryview(bytes(5))
NoneType x = None

How to check data types?

1
2
3
4
5
6
x = 5
print(type(x))
y = True
print(type(y))
z = "Hello Eunice"
print(type(z))

<class ‘int’>
<class ‘bool’>
<class ‘str’>