Python Basic Syntax - Cú pháp cơ bản trong Python

Các cú pháp cơ bản của Python

- Kiểm tra phiên bản của Python:

$ python
Python 2.4.3 (#1, Nov 11 2010, 13:34:43)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

- Nhập đoạn code sau đây và nhấn Enter:

>>> print "Hello, Python!"

Output:

Hello, Python!

- Lập trình trình Python script mode:

test.py

#!/usr/bin/python

print "Hello, Python!"
$ chmod +x test.py     # This is to make file executable
$./test.py

Output:

Hello, Python!

- Từ khóa trong Python:

and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield

Revision #2
Created 8 November 2019 15:09:21 by Laptrinh.vn
Updated 5 June 2021 15:01:36 by Laptrinh.vn