python小白之路(基礎知識一)

來源:互聯網
上載者:User

標籤:com   coding   base   nic   判斷   odi   tuple   算數運算   運算   

一、開篇輸出:print("Hello World!")

二、中文自由行:#coding=utf-8 或 # -- coding:UTF-8 --

三、Linux多行:#!/usr/bin/python

四、不能少的注釋:
1、#單行注釋
2、‘‘‘多行注釋’’’

五、標識符由字母、底線、數字組成,且數字不能開頭

六、不能修改和使用的關鍵詞
import keyword
keyword.kwlist

七、命名規範:
1、見名知意
2、駝峰命名法

八、字串的格式化:
1、"我叫%s,今年%d歲了" %(name, age))
2、"我叫{0},今年{1}歲了" .format(name,age)

九、輸入:input()接收運算式輸入,並把運算式的結果賦值給等號左邊的變數
name = input("請輸入姓名:")
age = int(input("請輸入年齡:"))

十、運算子:
1、算數運算子:+、-、*、/、//、%、*
2、賦值運算子:=
3、複合賦值運算子:+=、-=、
=、/=、//=、%=、**=

十一、常用資料類型轉換
int(x [,base])、long(x [,base ])、float(x )、complex(real [,imag ])、str(x )、repr(x )、eval(str )、tuple(s )、list(s )、chr(x )、unichr(x )、ord(x )、hex(x )、oct(x )

十二、判斷語句介紹:IF
如果某些條件滿足,才能做某件事,而不滿足時不允許做。日常如火車站安檢。

十三、比較、關係運算子
1、 比較(即關係)運算子:==、!=、<>、>、<、 >=、<=
2、邏輯運算子:and or not

python小白之路(基礎知識一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.