W3schools - Python_Intro
찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요
Python
Is a popular programming lang
It was created by Guido van Rossum, and released in 1991
It is used for
web development(server-side)
software development
mathematics
system scripting
Good
It works on different platform(Windows, Mac, Linux, Rasberry Pi,…)
Was designed for readability, and has some similarities to the Eng with influence from math
Runs on an interpreter system, meaning that code can be executed as soon as it is written
Can be treated in a procedural way, an object-oriented way or a functional way
Know
The most recent major version of Python is Python3
However, Python2, although not being updated with anything other than security updates, is still quite popular
Install
Many PC will have python already installed
To check if you have python installed on Mac open the Terminal and type python --version
If do not have Python installed on computer, then can download it from www.python.org
Start
Write Python file called “helloworld.py”, which can be done in any text editor
print(“Hello, World!”)
Save file and open command line, navigate to the directory where file was saved, and run
~/Desktop python helloworld.py
The output should read
Hello, World!
Command Line
To test a short amount of code in python sometimes it is quickest and easiest not to write the code in a file
This is made possible because Python can be run as a command line itself
Type the following on Mac command line
~ > python
From there you can write any python code
Python 3.9.7 (default, Sep 16 2021, 08:50:36)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print(“Hello, World!”) # Which will write “Hello, World!” in the command line
# Whenever you are done in the python command line, type the following to quit the python command line interface
exit()
Syntax
Execute
Python syntax can be executed by writing directly in the Command Line
Or by creating a python file on the server, using the .py file extension, and running it in the Command Line
Indentation
Refers to the spaces at the beginning of a code line
Where in other programming langs the indentation in code is for readability only, the indentation in Python is very important
Python uses indentation to indicate a block of code, Python will give an error if you skip the indentation
The number of spaces is up to programmer, but it has to be at least one
Have to use the same number of spaces in the same block of code, otherwise Python will give an error
Variables
Are created when you assign a value to it
x = 5
y = “Hello, World!”
Python has no command for declaring a var
Comments
Can be used to explain Python code
Can be used to make the code more readable
Can be used to prevent execution when testing code
# This is a comment, it starts with a “#”, and Python will ignore them
print(“Hello, World!”) # Comments can be placed at the end of a line, and Python will ignore the rest of the line
Python does not really have a syntax for multi line comments
But, not quite as intended, can use a multiline string
“””
Since Python will ignore string literals that aren’t assigned to a var,
you can add a multiline string(triple quotes) in your code, and place your comment inside it
”””