编程通识教育-01-基础入门

Programming Tutorial

01 Basics

Installation

Windows:
Visit https://www.python.org/downloads/ and download the latest version.

MacOS:
Use homebrew,

brew install python3

Linux:

sudo apt-get update && sudo apt-get install python3

Editor &Input method

In any text editor(vim, Sublime) or IDE(Pycharm, Spyder), use English input method, not Chinese.

print("hello, world“)
  File "<ipython-input-5-43e9612f56f8>", line 1
    print("hello, world“)
                         ^
SyntaxError: EOL while scanning string literal

**IMPORTANT: **

Always ensure that you give it the file extension of .py , for example, foo.py .

Comments

Notes for the reader of the program.

# Write your comments at this line in python
// Write your comments at this line in java
// Write your comments at this line in go

Literal Constants

Numbers or Strings, use its value literally.

Numbers

Numbers are mainly of two types - integers and floats.

print(18) #integer
print(3.14) #floats

Strings

A string is a sequence of characters. Strings are basically just a bunch of words.

print("hello,world") #string

Hello, World

#create hello.py
print("hello,world") 

Compile & Run

Compile:Convert a source program(Source Code) and the things it depends on into instructions in native machine language(Binary Code for Go) or intermediate code(Bytecode/class file for Java, python bytecode/pyc file for python).

Run: Excuting the binary code.

To run your Java program:

  1. Open a terminal window in MacOS (cmd in Windows OS)

  2. Change directory to where you saved the file, for example, cd /tmp/java

  3. Compile the program by entering the command javac hello.java .

$ javac hello.java

If you success in compile process, no text will be shown at the console. However, you will get a new file hello.class in the same directory as hello.java.

  1. Run the program by entering the command java hello.py . The output is as shown
    below.
$ java hello
hello world 

To run your Python program:

  1. Open a terminal window in MacOS (cmd in Windows OS)

  2. Change directory to where you saved the file, for example, cd /tmp/py

  3. Compile &Run the program by entering the sole command python hello.py . The output is as shown

below.

$ python hello.py 
hello world 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值