日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

笨方法python_笨方法学习Python(11-20)

發布時間:2024/7/23 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 笨方法python_笨方法学习Python(11-20) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下學習內容以python2為基準

11、提問print "How old are you?",

age = raw_input()

print "So, you're %r old." % age

python ex11.py

How old are you? 35

So, you're '35' old

input()與raw_input()都是Python的內建函數,實現與用戶的交互,但是功能不同。

raw_input可代表任意字符串

input在字符串上要加‘ ’

int類型最好使用input

12、提示別人

對于 raw_input 而言,你還可以讓它顯示出一個提示,從而告訴別人應該輸入什么東西。你可以在 () 之間放入一個你想要作為提示的字符串,如下所示:

y = raw_input("Name? ")

pydoc是python內置的官方文檔,類似于linux中的man

13、參數、解包、變量from sys import argv

script, first, second, third = argv

print "The script is called:", script

print "Your first variable is:", first

print "Your second variable is:", second

print "Your third variable is:", third

python ex13.py first 2nd 3rd

The script is called: ex13.py

Your first variable is: first

Your second variable is: 2nd

Your third variable is: 3rd

14、提示和傳遞from sys import argv

script, user_name = argv

prompt = '>'

print "Hi %s, I'm the %s script." % (user_name, script)

print "I'd like to ask you a few questions."

print "Do you like me %s?" % user_name

likes = raw_input(prompt)

print "Where do you live %s?" % user_name

lives = raw_input(prompt)

print "What kind of computer do you have?"

computer = raw_input(prompt)

print """

Alright, so you said %r about liking me.

You live in %r. Not sure where that is.

And you have a %r computer. Nice.

""" % (likes, lives, computer)

$ python ex14.py Zed

Hi Zed, I'm the ex14.py script.

I'd like to ask you a few questions.

Do you like me Zed?

> yes Where do you live Zed?

> America What kind of computer do you have?

> Tandy

Alright, so you said 'yes' about liking me.

You live in 'America'. Not sure where that is.

And you have a 'Tandy' computer. Nice.

15、讀取文件$ vi ex15_sample.txt

This is stuff I typed into a file.

It is really cool stuff.

Lots and lots of fun to have in here.

我們要做的是打開 ex15_sample.txtfrom sys import argv

script, filename = argv

txt = open(filename)

print "Here's your file %r:" % filename

print txt.read()

print "Type the filename agein:"

file_again = raw_input(">")

txt_again = open(file_again)

print txt_again.read()

16、讀寫文件from sys import argv

script, filename = argv

print "We're going to erase %r." %filename

print "If you don't want that, hit CRIL-C(^C)."

print "If you do want that, hit RETURN."

raw_input("?")

print "Opening the file..."

target = open(filename, 'w')

print "Truncating the file. Goodbye!"

target.truncate()

print "Now I'm going to ask you for three lines."

line1 = raw_input("line 1: ")

line2 = raw_input("line 2: ")

line3 = raw_input("line 3: ")

print "I'm going to write whese to the file."

target.write(line1)

target.write("\n")

target.write(line2)

target.write("\n")

target.write(line3)

target.write("\n")

print "And finally, we close it."

target.close()

17、更多文件操作

from os.path import exists

print "%r" % exists(to_file) #查看to_file有有沒用存在,會返回布爾值

print "d%" % len(indata) #查看有多少個字節

# 朝to_file里寫入數據,寫入indata

output = open(to_file, 'w')

output.write(indata)

output.close() #關閉

18、命令、變量、代碼、函數#coding:utf-8

def nan_nad_nv(nan_count,nv_count):

print "我們IT男生有%d。" % nan_count

print "我們IT女生有%d。" % nv_count

print "IT人員數目為:"

>>> nan_nad_nv(60,20)

結果

IT人員數目為:

我們IT男生有60。

我們IT女生有20。

19、函數和變量def cheese_and_crackers(cheese_count, boxes_of_crackers):

print "You have %d cheeses!" % cheese_count

print "You have %d boxes of crackers!" % boxes_of_crackers

cheese_and_crackers(20, 30)

結果

You have 20 cheeses!

You have 30 boxes of crackers!

amount_of_cheese = 10

amount_of_crackers = 50

cheese_and_crackers(amount_of_cheese, amount_of_crackers)

結果

You have 10 cheeses!

You have 50 boxes of crackers!

20、函數和文件

掌握以下參數意義

f.seek(0)

f.readline()

原文地址:http://blog.51cto.com/8672771/2073551

總結

以上是生活随笔為你收集整理的笨方法python_笨方法学习Python(11-20)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧美日韩另类视频 | 91蜜桃婷婷狠狠久久综合9色 | 天天舔天天插 | 色婷婷狠狠操 | 亚洲视频欧洲视频 | av大片在线观看 | 91高跟黑色丝袜呻吟在线观看 | 黄网av| 日本视频一区二区 | 日韩av在线不卡 | 精品国产露脸精彩对白 | 久久免费视频观看 | 女王脚交玉足榨精调教 | 视频在线观看视频 | 日韩有码视频在线 | 奇米精品一区二区三区在线观看 | 久久福利一区 | 色狠狠一区二区 | 强开小受嫩苞第一次免费视频 | 中文在线一区二区 | 日韩福利视频网 | 五月天色站| 青青青网 | 1级片在线观看 | 91亚洲免费| 久久免费视频精品 | 台湾黄色网址 | 麻豆伊甸园 | 成人黄色激情 | 欧美巨乳在线 | 亚洲一区二区在线观看视频 | 日韩精品久久久久久久 | a√在线视频 | 成人网在线 | 极品久久| 国产成人无码网站 | 97av.com| 欧美视频一区二区三区 | 久久婷婷久久 | 思思99精品视频在线观看 | xxxwww黄色 | 国产精品自拍区 | 国产三级av在线播放 | 日韩欧美少妇 | 免费国产网站 | www.国产91 | 神马午夜在线 | 久久精品2019中文字幕 | 国产18在线 | 成人日批视频 | 91激情捆绑调教喷水 | 色漫| 日本三级欧美三级 | 国产农村妇女毛片精品久久麻豆 | 午夜爱爱免费视频 | 逼特逼在线视频 | 夜夜夜夜夜操 | 美女黄色免费网站 | 91精品久久久久久久久久 | 激情五月深爱五月 | 久久精品国产精品亚洲毛片 | 韩国一区二区三区在线观看 | 日韩电影三级 | 99re最新网址 | 奇米97| av中文字幕网址 | 亚洲不卡网 | 天天草天天爽 | 国产精品网站入口 | 国产毛片aaa| 91麻豆精品 | 精品日韩一区二区三区四区 | 男人天堂亚洲 | 超碰麻豆| 3d动漫精品啪啪一区二区免费 | 国产精品日韩无码 | 污网站免费在线观看 | 国产裸体视频网站 | 国产久一 | 天天久久 | 亚洲少妇视频 | 成都电影免费大全 | 亚洲欧洲一区 | 新天堂在线 | 欧美三级午夜理伦三级老人 | 中文字幕大全 | 久久黄色视 | 麻豆观看| 午夜九九九 | 偷拍久久久| 年代下乡啪啪h文 | 欧美日本韩国一区 | 国产精品一区二区黑人巨大 | 体内精视频xxxxx | 国产精品乱码一区二区视频 | 中文字幕第七页 | 美女极度色诱图片www视频 | 久久久久久久一 | 精品人妻无码一区二区三区换脸 |