develog

[python] 설치, 실행, syntax 본문

카테고리 없음

[python] 설치, 실행, syntax

냐옴 2021. 5. 24. 00:40

python 설치

version 확인

python --version

python 실행

python test.py
py test.py

comment

# line comment

"""
  block comment
"""

function

# function 정의
def aa():
    print("aa called")

# function 실행
aa()
# funciton 정의
def sum(a, b):
    c = a + b
    return c

# function 실행
print(sum(1, 2))

boolean

a = True
if a:
    print("true")

a = False
if not a:
    print("false")

a = True
b = True
if a == b:
    print("all True")

uppercase, lowercase

print("Python".upper())
print("Python".lower())

string index

str = "aa.bb.txt"
firstIndex = str.find(".") + 1
lastIndex = str.rfind(".") + 1
print(firstIndex) # 3
print(lastIndex)  # 6
print(str[firstIndex:]) # bb.txt
print(str[lastIndex:])  # txt

list length

list = ["aa", "bb", "cc"]
len = list.__len__() # 3
for i in range(0, len):
    print(list[i])
"""
aa
bb
cc
"""

dictionary

dict = {
    "name": "james",
    "age": 20
}
print(dict) # {'name': 'james', 'age': 20}
Comments