Python (Basics)

2022. 1. 2. 10:52Python/Python 기초 (Basics)

반응형

Python (Basics)

Learn the basics of the Python programming language.

The sequence is as follows.

 

(Keyword)

(Keyword) is a string that is already reserved in the Python language,

It cannot be used as the name of a variable or function, etc.

There are 33 keywords in Python, as listed below.

False, None, True, and, as, assert, break, class, continue, def,
del, elif, else, except, finally, for, from, global, if, import,
in, is, lambda, nonlocal, not, or, pass, raise, return, try,
while, with, yield

If you run the code below in Python, you can check the keywords in the form of a list.

 

 

import keyword

print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

False, None, True

Only the above three keywords start with an uppercase letter, and all other keywords must be written with a lowercase letter.

For examples and explanations of each keyword, see the Python Keywords page.

 
 

(Identifier)

(Identifier) ​​is used to identify objects such as variables, functions, and classes.

There are several rules for choosing an identifier:

 

For example, if you use the Python keyword as the name of a variable, as in the example below,

def = 1

print(def)
SyntaxError: invalid syntax

A SyntaxError will be raised.

 
 

(Indentation)

In contrast to the use of parentheses such as { } in programming languages ​​such as C, C++, and Java, indentation is used in Python.

Use the tab key or two or four spaces to separate the inner regions of if statements, for statements, and functions.

Indentation makes your code more readable and clean looking.

 

Indentation example.

 

Example 1

if True:
    print('Hello')
    a = 5
if True: print('Hello'); a = 5

The above two codes perform the same function, but the first one is more readable.

 

 

Example 2

for i in range(10):
    print(i)
    if i == 5:
        break

Use single indentation within for statements, if statements, etc.

 

 
 

(Comment)

(Comment) refers to a piece of code that is not executed.

It is mainly used to explain the meaning of the code and to make it easier to understand.

When using comments in Python, use the hash sign (#) as shown below.

 

single line comment

# This is a single line comment.

print('Hello, world!')      # 'Hello, world!

To comment out a line, put a hash symbol in front of that line.

You can also add comments to the end of the code using hash symbols.

(It depends on the editor, but you can easily comment out the entire line by using the ‘Ctrl+/’ shortcut key.)

 

multiline comment 1

# This is
# A multi line comment.

To use more than one line of comments, just put a hash symbol in front of each line.

 

 

multiline comment 2

''' This is
Also a multi line
Comment. '''

You can comment out multiple lines using either single quotation marks (‘’) or three double quotation marks (“”).

 

 

 

If the material was helpful, please subscribe and like it on YouTube Onya TV below!

https://www.youtube.com/channel/UCKEjO6sQJjlyzbHGeqd3hKg

 

ONYA TV 오냐TV

오늘의 인터뷰 오냐TV 입니다. 벤처 또는 신규 기업, 새롭고 다양한 것을 생생하게 인터뷰 하는 오냐TV 채널 입니다. 새로운 상품이나 서비스 등 소개를 '유튜브'에서 전달하고 있고, "오냐TV" 영상

www.youtube.com

 

There is a small honey gain income as passive income, so please check the contents below as well~^^
(Refers do not receive $5, so be sure to click on it for your own benefit.)

https://r.honeygain.money/OLIVE47A16

 

Passive Income - Effortlessly | Honeygain

Honeygain is the first-ever app that allows users to make money online by sharing their internet connection.

www.honeygain.com

 

Copyright 2021. beauty886699.tistory.com

반응형

'Python > Python 기초 (Basics)' 카테고리의 다른 글

파이썬 퍼센트 구하기  (0) 2022.01.11