python代碼

  • 原始字符串,不做任何特殊的處理
  • print("Newlines    are    indicated    by    \n")#Newlines are indicated by print(r"Newlines are indicated by \n")#Newlines are indicated by \n
  • 格式輸出,轉化為字符串由format自動完成
  • age    =    20 
    name    =    'Swaroop'
    print('{0} was {1} years old when he wrote this book'.format(name, age))
  • 元組字典做函數參數
  • def    total(a=5,    *numbers,    **phonebook):                print('a',    a)    for    single_item    in    numbers:                                print('single_item',    single_item)for    first_part,    second_part    in    phonebook.items():                                print(first_part,second_part)
    print(total(10,1,2,3,Jack=1123,John=2231,Inge=1560))
  • 字符串連接鏈表
  • delimiter    =    '____' 
    mylist    =    ['Brazil',    'Russia',    'India',    'China'] 
    print(delimiter.join(mylist))#Brazil____Russia____India____China
  • 類變量、方法,對象變量、方法
  • class Robot:'''表示有一個帶有名字的機器人。'''#類變量population = 0__population2 = 0#雙下劃線代表私有def __init__(self, name):#對象變量self.name = nameself.__name2 = name#雙下劃線代表私有Robot.population += 1#對象方法def die(self):Robot.population -= 1#類方法,用classmethod定義
        @classmethoddef how_many(self):print("We have {:d} robots.".format(self.population))
    Robot("蔣凱楠").how_many()
  • 代碼中有中文導致的錯誤加入下面的代碼,注意別忘了等號
  • # coding=gbk
  • try--except--else
    try--except--finally
  • #coding=gbk
    '''
    try--except--else
    try--except--finally
    else只在沒有異常時執行,有異常時不執行else
    finally一定會被執行,無論有沒有異常
    except在異常匹配時執行
    '''
    import time
    try:for i in range(1, 2, 1):print(i)time.sleep(1)raise KeyboardInterrupt()
    except KeyboardInterrupt:print("CTRL+C后,except執行了")
    finally:print("CTRL+C后,finally執行了")

    ?

    ?

轉載于:https://www.cnblogs.com/jkn1234/p/8797947.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390713.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390713.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390713.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Linux 設備管理和進程管理

設備管理 Linux系統中設備是用文件來表示的,每種設備都被抽象為設備文件的形式,這樣,就給應用程序一個一致的文件界面,方便應用程序和操作系統之間的通信。 設備文件集中放置在/dev目錄下,一般有幾千個,不…

樂高ev3涉及到的一些賽事_使您成為英雄的前五名開發者技能(提示:涉及LEGO)

樂高ev3涉及到的一些賽事Programming is like building something with LEGOs. Any developer can pick up a brand new LEGO set and build it following the instructions. This is very easy. Think of it as coding school assignments or entry level tutorials.編程就像用…

貝葉斯 定理_貝葉斯定理實際上是一個直觀的分數

貝葉斯 定理Bayes’ Theorem is one of the most known to the field of probability, and it is used often as a baseline model in machine learning. It is, however, too often memorized and chanted by people who don’t really know what P(B|E) P(E|B) * P(B) / P(E…

winfrom 點擊按鈕button彈框顯示顏色集

1.窗體托一個按鈕button; 2.單擊事件: 1 private void btnForeColor_Click(object sender, EventArgs e)2 {3 using (ColorDialog cdialog new ColorDialog())4 {5 cdialog.AnyColor true;6 …

JavaScript時間事件:setTimeout和setInterval

Programmers use timing events to delay the execution of certain code, or to repeat code at a specific interval.程序員使用時序事件來延遲某些代碼的執行,或以特定的時間間隔重復代碼。 There are two native functions in the JavaScript library used to …

webservice 基本要點

webservice的特點 webservices是自我包含的 webservices是自我描述的 webservices是跨平臺和語言的 webservices是基于開放和標準的 webservices是可以組合的 webservices是松散耦合的 webservices提供編程訪問的能力 webservices通過網絡進行發布,查找和使用 發布w…

文本數據可視化_如何使用TextHero快速預處理和可視化文本數據

文本數據可視化自然語言處理 (Natural Language Processing) When we are working on any NLP project or competition, we spend most of our time on preprocessing the text such as removing digits, punctuations, stopwords, whitespaces, etc and sometimes visualizati…

Less變量

Less變量 定義變量 Less 中的變量和其他編程語言一樣,可以實現值的復用,同樣它也有作用域(scope)。簡單的講,變量作用域就是局部變量和全局變量的概念。 Less 中,變量作用域采用的是就近原則,換…

漸進式web應用程序_如何在漸進式Web應用程序中添加到主屏幕

漸進式web應用程序添加到主屏幕 (Add To Homescreen) Here the web app install banner is focused on web app, with the feature of add to homescreen.在此,Web應用程序安裝標語專注于Web應用程序,具有添加到主屏幕的功能。 瀏覽器對“添加到主屏幕”…

linux shell 編程

shell的作用 shell是用戶和系統內核之間的接口程序shell是命令解釋器 shell程序 Shell程序的特點及用途: shell程序可以認為是將shell命令按照控制結構組織到一個文本文件中,批量的交給shell去執行 不同的shell解釋器使用不同的shell命令語法 shell…

Leetcode之javascript解題(No33-34)

附上我的github倉庫,會不斷更新leetcode解題答案,提供一個思路,大家共勉 在我的主頁和github上可以看到更多的關于leetcode的解題報告!(因為不知道為什么掘金沒有將其發布出來,目前已經聯系掘金客服&#x…

真實感人故事_您的數據可以告訴您真實故事嗎?

真實感人故事Many are passionate about Data Analytics. Many love matplotlib and Seaborn. Many enjoy designing and working on Classifiers. We are quick to grab a data set and launch Jupyter Notebook, import pandas and NumPy and get to work. But wait a minute…

轉:防止跨站攻擊,安全過濾

轉:http://blog.csdn.net/zpf0918/article/details/43952511 Spring MVC防御CSRF、XSS和SQL注入攻擊 本文說一下SpringMVC如何防御CSRF(Cross-site request forgery跨站請求偽造)和XSS(Cross site script跨站腳本攻擊)。 說說CSRF 對CSRF來說,其實Spring…

Linux c編程

c語言標準 ANSI CPOSIX(提高UNIX程序可移植性)SVID(POSIX的擴展超集)XPG(X/Open可移植性指南)GNU C(唯一能編譯Linux內核的編譯器) gcc 簡介 名稱: GNU project C an…

html怎么注釋掉代碼_HTML注釋:如何注釋掉您HTML代碼

html怎么注釋掉代碼HTML中的注釋 (Comments in HTML) The comment tag is an element used to leave notes, mostly related to the project or the website. This tag is frequently used to explain something in the code or leave some recommendations about the project.…

k均值算法 二分k均值算法_使用K均值對加勒比珊瑚礁進行分類

k均值算法 二分k均值算法Have you ever seen a Caribbean reef? Well if you haven’t, prepare yourself.您見過加勒比礁嗎? 好吧,如果沒有,請做好準備。 Today, we will be answering a question that, at face value, appears quite sim…

您好,這是我的第一篇文章

您好我是CYL 這是一個辣雞博客 歡迎指教 轉載于:https://www.cnblogs.com/pigba/p/8823472.html

08_MySQL DQL_SQL99標準中的多表查詢(內連接)

# sql99語法/*語法: select 查詢列表 from 表1 別名 【連接類型】 join 表2 別名 on 連接條件 【where 篩選條件】 【group by 分組】 【having 分組后篩選】 【order by 排序列表】分類內連接(重點): inner外連接 左外&#xff0…

java中抽象類繼承抽象類_Java中的抽象類用示例解釋

java中抽象類繼承抽象類Abstract classes are classes declared with abstract. They can be subclassed or extended, but cannot be instantiated. You can think of them as a class version of interfaces, or as an interface with actual code attached to the methods.抽…

新建VUX項目

使用Vue-cli安裝Vux2 特別注意配置vux-loader。來自為知筆記(Wiz)