• Skip to main content
  • Skip to primary sidebar
…

...

cuộc sống là phải luôn khám phá.

  • Home
  • Music Box
  • Các trang web hay
  • Giới thiệu
  • Liên kết website
Bạn đang ở đây:Trang chủ / IT / Python Basic: Getting to Python (part 1)

Python Basic: Getting to Python (part 1)

20/10/2021 tác giả: Mạnh Hùng 6 Bình luận

Python Basic: Getting to Python (part 1) 1

Introduction to Python

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming.

Some of the outstanding features of Python include:

  • Clear, easy-to-read syntax.
  • Object-oriented.
  • Fully modular, supports hierarchical packages.
  • Lots of standard libraries and extensive external modules.
  • Exception-based error handling.
  • High-level dynamic data type, data type interpolation
  • External modules can be written in C, C++, Jython …
  • Machine learning, statistical computing, data analysis.
  • Powerful and fast.

Python Resources:

  • Learn Python Treehouse: https://teamtreehouse.com/learn-to-code/python
  • Learn Python The Hard Way: https://learnpythonthehardway.org
  • Learn Python Code Mentor: https://www.codementor.io/learn-python-online
  • Visualize Python: https://www.pythontutor.com
  • Learn Python Code Academy: https://www.codecademy.com/learn/python
  • Python Tutorial: https://www.w3schools.com/python
  • Real Python: https://realpython.com
  • r/Python
  • And Google, or course…

Ebooks:

  • Fundamentals of Python Programming – Richard L. Halterman
  • Learn Python 3 the hard way – Zed A. Shaw
  • Programming in Python 3 – Mark Summerfield
  • Python Algorithms – Magnus Lie Hetland
  • …

Programming tools:

  • Notepad, Notepad++
  • IDLE
  • Wing Python IDE
  • Pycharm (recommended)

Download Python: https://www.python.org/downloads

Python install steps:

These steps assume that you’re a Windows user, however, if you’re using Linux or Mac, then there should be plenty of how-to guides on internet, and by the way the book Learn Python 3 the hard way has very detailed setup introduction for each platform.

python install
(tick Add Python to PATH and choose Customize)
python install
(tick all options)
python install
(if you use Visual Studio, tick last option, or can leave it blank)

Check if Python is installed properly:

Go to command line by typing cmd in Windows Search (Windows key + R), then at the command prompt, type python. If it’s shown like below, then you have installed Python correctly.

Python Basic: Getting to Python (part 1) 2
(I’m using a different, nicer version of command-line interface called cmder)

Create a Python project in Pycharm

Pycharm Community Edition is enough for beginners and advance users alike to learn and work with Python. You could learn more about what is the difference between Community and Professional Edition by reading this article.

When you start Pycharm, you should see this window. Click Create New Project.

Python Basic: Getting to Python (part 1) 3

Location: Specify where you want to save your Python project.

Press small arrow before Python Interpreter to show the interpreter configuration. Choose the second option here, then press [ … ] to go to next step. At Add Python Interpreter window, pick System Interpreter option, then press [ … ] button to find path to python.exe (it should look like my path in the above image, replace with <your_username> between C:\Users\… and …\AppData\Local…)

To create new Python file, right click your project folder on the sidebar, then go to New -> choose Python File.

Python Basic: Getting to Python (part 1) 4

Now you have a blank Python file. Let’s try a few simple code. Don’t worry about these code, I will go back to explain how it works at later articles.

Python Basic: Getting to Python (part 1) 5

Then, click Run Python Basic: Getting to Python (part 1) 6 button, or press Shift + F10.

You can see result at the console below, by looking at Run tab:

Python Basic: Getting to Python (part 1) 7

And that’s it. We could prepare for next stage now.

Basic data types in Python

int : represent integers include zero, positive or negative whole numbers without a fractional part and having unlimited precision. For example: 124, -115

float : floating point numbers are positive and negative real numbers with a fractional part denoted by the decimal symbol . or the scientific notation E or e, for example: 1834.59, 3.142, -4.45, 0.713, 1.2e6, 8e-3

complex : complex number is a number with real and imaginary components. For example, 8 + 3j is a complex number where 8 is the real component and 3 multiplied by j is an imaginary component. Note: You must use j or J as imaginary component, as sing other character the program will throw a syntax error. For complex number, instead of typing a+bj, you could also use complex(a, b) function.

# example with a = 2; b = 3
z = complex(2, 3)
print("Real part =", z.real)
print("Imaginary part =", z.imag)
# Return: Real part = 2.0, Imaginary part = 3.0

str : the sequence of Unicode characters wrapped inside single, double, or triple quotes. ‘Python’ ; “Python” ; ”’Python”’ or “””Python”””.

bool: Boolean type, store as True or False.

Declare variables in Python

In Python, a variable does not need to declare a data type, but when we assign a value to it, Python will automatically interpolate the data type of the variable. Thus, a variable can have many data types depending on the assigned value. We can use the type() function to check the data type of a variable. (different from other language like C, Java…)

A variable need to begin with a character, so a1 will work, but 1a will not.

Delete variables

If an existing variable is deleted, it cannot be used anymore. Using statement del x (with x is a variable) to delete.

Check storage area

We can check the value storage area of int and float variables by importing the sys library to see the details.

import sys
print("int info: ")
print(sys.int_info)
print("float info: ")
print(sys.float_info)
# result:
# int info: 
# sys.int_info(bits_per_digit=30, sizeof_digit=4)
# float info: 
# sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)

Continue to part 2.

Reader Interactions

Trackbacks

  1. Python Basic: Getting to Python (part 2) - ... viết:
    20/10/2021 lúc 9:05 chiều

    […] check part 1 first and then come back to read this article […]

    Trả lời
  2. Python Basic: Getting to Python (part 4) - ... viết:
    22/10/2021 lúc 6:33 chiều

    […] that here the second or third index is belong to str element, since string is also a sequence data […]

    Trả lời
  3. Huawei HG8045A - Hướng dẫn cấu hình làm access point. - ... viết:
    23/10/2021 lúc 10:57 sáng

    […] Python Basic: Getting to Python (part 1) […]

    Trả lời
  4. SHA-1 là gì ? - ... viết:
    24/10/2021 lúc 2:38 chiều

    […] https://pquan.info/python-basic-getting-to-python-part-1/ […]

    Trả lời
  5. [APlayer] How to make a elegant HTML5 web music player for your website - ... viết:
    24/10/2021 lúc 10:00 chiều

    […] https://pquan.info/python-basic-getting-to-python-part-1/ […]

    Trả lời
  6. (Cmder) Thay thế hiệu quả cho Command Prompt trên Windows - ... viết:
    25/10/2021 lúc 5:53 chiều

    […] bài viết trước về Python Basic có nhắc đến Cmder, thì bài viết dưới đây nói sơ lược về Cmder cho các bạn […]

    Trả lời

Để lại bình luận: Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Primary Sidebar

Chuyên mục

  • fun
  • IT
  • News
  • testing

python

Python Basic: Getting to Python (part 4)

In short, Lists are used to store multiple items in a single variable, they are convenient data structures for representing a sequence of data. In that regard, a list is similar to a string, except a string can hold only characters, however, a list can hold any Python object.

python

Python Basic: Getting to Python (part 3)

Python Functions: (user-defined or from libraries) function is a block of code which only runs when it is called, to do a complete job (module), is named, and can be called to execute multiple times at many places in the program. What happens if you don’t use function? What I can think about is repetitive works, hard to debug, hard to expand the whole code, so usually when working on a large project you need to split your code into many small modules.

Tạo một website dễ dàng với Hugo

Hôm nay chúng ta cùng thử generate 1 website với Hugo, theo như lời giới thiệu ở trang chủ “The world’s fastest framework for building websites.”

Steam_logo

DMCA.com Protection Status

Copyright ©2022 · pquan.info - All Rights Reserved ·