Python
Contents
Download & installation
it can be downloaded from https://www.python.org/
in command prompt type
python3
to run new version
Creating a new programme
create a file with extension .py
print("Hello world")
print("*" * 10)
Run it with python3 app.py the result will be
Hello World **********
VS Code Extensions for Python
Python
it's a Microsoft extension for Linting, Debugging, intellisense, code formatting, refactoring
in vs Code bottom left corner change version to new one by clicking it and click pylint message to install it.
Code Runner
By Jun Han with yellow .run logo
Ctrl + Alt + N to run code automatically
in preferences -> extra ... -> user settings -> code-runner-executorMap -> update python to python3
(on the right side after the last settings type "code-runner-executorMap" and hit enter. Then change it.
Variables
x = 1 y = 2
instead we can use
x, y = 1, 2
boolean
is_published = True
string
course="Python Programming" print(len(course)) -> 18 print(course[0]) -> P print(course[-1]) -> g
slicing
print(course[0:3]) -> Pyt print(course[:3]) -> Pyt
Case
print(course.upper()) -> PYTHON PROGRAMMING print(course.lower()) -> python programming print(course.title()) -> Python Programming
trim
print(course.rstrip()) print(course.lstrip()) print(course.strip())
substring
print(course.find("Pro"))
print(course.replace("P", "-"))
print("Pro" in course)
print("Pro" not in course)
Shift + Cmd + M -> opens Problem window
Shift + Cmd + P -> Command Palette -> Format Document ->
Preferences -> FormatOnSave -> True : Formats doc on save