「Hello, World!」程式通常指輸出或顯示「Hello, World!」字串的電腦程式。可以用來展示該程式語言的基本語法。
「Hello, World!」是初學者學習某種程式語言所接觸的第一個程式內容,。
第一個程式:
print("Hello, World!")
output:
Hello, World!
console.log('Hello World');
class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
#include <iostream> using namespace std; int main() { cout << "Hello! World!"; return 0; }
global _start ; This exports _start label and ; makes entry point to the programing ; ########################## ; code ; ########################## section .text _start: ; ########################## ; write(1, message, length) ; ########################## mov rax, 1 ; system call for write mov rdi, 1 ; making file handle stdout mov rsi, message ; passing adress of string to output mov rdx, length ; number of bytes syscall ; invoking os to write ; ########################## ; exit(0) ; ########################## mov rax, 60 ; sys call for exit xor rdi, rdi ; exit code 0 syscall ; invoke os to exit ; ########################## ; Variables ; ########################## section .data message: db "Hello, World", 0xa ; const char * message = "Hello, World"oxa is "\n" length: equ $-message; int length= len(message) =12;
例題一
word = input() print(----, word)
print([object], separator, end, file, flush)
其中只有sep和end常用
預設為 sep = " " (space)
print("hello", "world") print("hello", "world", sep = " ") print("hello", "world", sep = "") print("hello", "world", sep = "啟動") print("hello", "world", "python", sep = "啟動")
output:
hello world
hello world
helloworld
hello啟動world
hello啟動world啟動python
預設為 end = "\n" (換行)
print("Hello, World!1") print("Hello, World!2", end = "\n") print("Hello, World!3", end = "") print("Hello, World!4") print("Hello, World!5", end = "啟動") print("Hello, World!6")
output:
Hello, World!1
Hello, World!2
Hello, World!3Hello, World!4
Hello, World!5啟動Hello, World!6
例題二
year = input() month = input() day = input() print(----)
name = input() print("hello", name)
output:
{User input}
hello {User input}
()內為等待輸入時,系統輸出的東西
name = input("what is your name? :") print("hello", name)
output:
what is your name? :{User input}
hello {User input}
表示方式 | 中文 | 英文 |
---|---|---|
int | 整數 | integer |
float | 浮點數 | floating point |
bool | 布林值 | boolean |
str | 字串 | string |
num1 = 120 num2 = 3.14159 num3 = 5 print(type(num1)) print(type(num2)) print(type(num3 == 5))
output:
<class 'int'>
<class 'float'>
<class 'bool'>
num1 = 120 num2 = 3.14159 print(type(num1)) print(type(num2)) num3 = float(num1) #將num3定為num1轉float的值 num4 = int(num2) #將num4定為num2轉int的值 print(num3) print(num4) print(type(num3)) print(type(num4))
output:
<class 'int'>
<class 'float'>
120.0 #多了小數點
3 #捨去小數部分(不是四捨五入,是無條件捨去)
<class 'float'>
<class 'int'>
num1 = 120 num2 = 3.14159 num3 = 5 print(type(num1), type(num2), type(num3 == 5), sep="/") str1 = str(num1) str2 = str(num2) str3 = str(num3 == 5) print(str1, str2, str3, sep = "/") print(type(str1), type(str2), type(str3), sep="/")
output:
<class 'int'>/<class 'float'>/<class 'bool'>
120/3.14159/True
<class 'str'>/<class 'str'>/<class 'str'>
str是純數字時可轉成int, float
str1 = "120" str2 = "3.14159" num1 = int(str1) num2 = float(str2) print(num1) print(type(num1)) print(num2) print(type(num2))
output:
120
<class 'int'>
3.14159
<class 'float'>
str1 = "HSNUCRC" print(len(str1)) print(str1[3]) print(str1[1:5])
7
U
SNUC