A useful note when using Python for the first time in a while

Role of indentation

In Python, indentation is used to represent blocks.

Also, the line ending with a colon (:) marks the beginning of the block.

if num == 1:
    print "One."
elif num == 2:
    print "Two."
else:
    print "N/A."

Shebang

As Shebang, write the following on the first line of the Python script.

#!/usr/bin/env python

Coding Style

Coding Style refers to PEP 8. PEP 8 is a Style Guide for Python compiled by the Python Community.

PEP 8 - Style Guide for Python Code https://www.python.org/dev/peps/pep-0008/

There is also a Japanese translation. http://pep8-ja.readthedocs.org/ja/latest/

--Indentation is "4 spaces" --Use lowercase letters and underscores for method names --Use lowercase letters and underscores for instance variables --Use uppercase letters and underscores for constant names

Sample code

sample.py


#! /usr/bin/env python
# -*- coding: utf-8 -*-

num = 5

for i in range(num):
    print i, ": Hello!"

Recommended Posts

A useful note when using Python for the first time in a while
MongoDB for the first time in Python
Register a task in cron for the first time
See python for the first time
Differences C # engineers felt when learning python for the first time
Try using FireBase Cloud Firestore in Python for the time being
I tried using scrapy for the first time
I tried python programming for the first time.
What I learned by writing a Python Pull Request for the first time in my life
Turn multiple lists with a for statement at the same time in Python
What I got into Python for the first time
I tried Python on Mac for the first time.
Initial settings when using the foursquare API in python
I tried python on heroku for the first time
Things to note when initializing a list in Python
Kaggle for the first time (kaggle ①)
Kaguru for the first time
A note on the library implementation that explores hyperparameters using Bayesian optimization in Python
How to unit test a function containing the current time using freezegun in python
A note for embedding the scripting language in a bash script
Try a similar search for Image Search using the Python SDK [Search]
Note 2 for embedding the scripting language in a bash script
Summary of stumbling blocks in Django for the first time
A memo when creating a directed graph using Graphviz in Python
[Note] Import of a file in the parent directory in Python
Note links that may be useful when using Python, Selenium2
Solve the Japanese problem when using the CSV module in Python.
Precautions when using pit in Python
[For self-learning] Go2 for the first time
Start Django for the first time
The first step in Python Matplotlib
When using regular expressions in Python
When writing a program in Python
Things to watch out for when using default arguments in Python
Effective Python Note Item 17 Respect for certainty when using iterators for arguments
[Python] Execution time when a function is entered in a dictionary value
A function that measures the processing time of a method in python
I get a can't set attribute when using @property in python
A note on using tab completion when running Python interactively on Windows
Put the process to sleep for a certain period of time (seconds) or more in Python
Code that I wish I had remembered when I participated in AtCoder for the first time (Reflection 1 for the next time)
The story of releasing a Python text check tool on GitHub x CircleCI for the first time
Settings for running a test each time you save a file in the editor using watchmedo (watchdog)
Introduction to Deep Learning for the first time (Chainer) Japanese character recognition Chapter 3 [Character recognition using a model]
The story of returning to the front line for the first time in 5 years and refactoring Python Django
Generate a first class collection in Python
Try using the Wunderlist API in Python
Precautions when pickling a function in python
Python Master RTA for the time being
Tweet using the Twitter API in Python
[python, multiprocessing] Behavior for exceptions when using multiprocessing
Run the Python interpreter in a script
Scraping a website using JavaScript in Python
Get a token for conoha in python
Draw a tree in Python 3 using graphviz
Let's try Linux for the first time
Notes for using python (pydev) in eclipse
I tried logistic regression analysis for the first time using Titanic data
[Python memorandum] Various time verifications ・ The first While statement is abnormally slow
[Python] Calculate the number of digits required when filling in 0s [Note]
A memo when setting up a Docker container for using JUMAN ++, KNP, python