Python complete tutorial
  • Python Complete Tutorial
  • About this book
  • What you need to prepare
  • 1️⃣Try python for the first time
    • Install python
    • Hello world!
    • Hello world in a nutshell
    • The first simple python project
    • most useful libraries
    • Recommended websites
  • 2️⃣Data structure and basic operations
    • Python data structure
    • Data structure without hash table
    • Data structure with hash table
    • Variability and address
    • basic python programming
    • basic python programming 2
    • basic python programming 3
    • some additions
    • Fibonacci sequence
    • Judging prime numbers
    • txt/csv file operation
  • 🐍Practice program
    • 🚩fancy print
    • 🚩Remove duplicate elements
    • 🚩Palindrome detection
  • 😎leetcode
    • what is leetcode
  • 3️⃣Data mining and machine learning
    • What is data mining
    • iris data set
    • Mean median mode
    • Harmonic mean
    • Histogram
    • Correlation algorithm
    • Gaussian distribution data set
    • projection
    • PCA
    • MDS
    • Bayesian and Frequentist
    • Data normalization
    • binary SVM
    • One Hot Encoding
    • Multi-class SVM
    • Accuracy and error rate
    • Confusion matrix & Accuracy, Precision, Recall
    • F1 score
    • ROC and AUC
  • 4️⃣big data and data visualization
    • line chart
    • Parallel coordinates
    • Histogram chart
  • 5️⃣Mathematical algorithm and digital signal processing
    • Mathematical constants and basic operations
    • Normal distribution
    • Permutation and combination
    • Bernoulli distribution
    • Chaotic system
  • 6️⃣Classes and design patterns
    • Classes and design patterns
  • 7️⃣Operate the database with python
    • MySQL
      • Install MySQL
      • First try MySQL
      • MySQL Architecture
      • database operations
      • database
  • 8️⃣Cryptography
    • beginning of Cryptography
  • 9️⃣deep learning
    • What is Deep Learning
    • basic
  • 💔algorithm
    • Algorithms and Data Structures
Powered by GitBook
On this page
  • assignment symbol
  • if __name__ == '__main__':
  • Statistics
  1. Data structure and basic operations

some additions

assignment symbol

>>> a = 4
>>> a += 3
>>> a
7
>>> 

a += 3 and a = a + 3 have the same meaning. This is an auto-increment operation.

Unlike C++ or Java, there is no such way as a++ in python, if you want a to increment by 1, then you need a += 1

All operators support auto-increment:

>>> a = 4

>>> a %= 2
>>> a
0

>>> a += 3
>>> a
3

>>> a -= 5
>>> a
-2

>>> a /= 4
>>> a
-0.5

>>> a *= 10
>>> a
-5.0

>>> a //= 6
>>> a
-1.0

>>> 

if __name__ == '__main__':

if __name__ == '__main__':
    print('hello world')

In Python, a .py file is a module. In general, the module name is the file name.

__name__ holds the current module name. When the module is run directly, the module name is __main__.

So, if __name__ == '__ main__': means: when the module is run directly, the code block below this line will be run; when the module is imported (import), the code block will not be run.

So in the main file, if __name__ == '__main__': should be added, and all your execution code should be placed under this condition. Because it makes the program more concise.

So in the package file, if __name__ == '__main__': is not necessarily required, you can add the statement that tests the function in the package file to this condition to test the correctness of the package, but when the main program calls this package file, these test statements will not be executed.

Statistics

Start time of this page: February 2, 2022

Completion time of this page: February 9, 2022

Previousbasic python programming 3NextFibonacci sequence

Last updated 3 years ago

2️⃣
Page cover image