1. 程式人生 > >To watch,need to Move on

To watch,need to Move on

Python3.5 函式的呼叫

望共同進步

轉載請註明地址:http://blog.csdn.net/weixin_39701039/article/details/79567006

寫函式的定義的時候其實已經呼叫了函式,如

#coding:utf-8
#python 3.5.1
def get_Square(x):
    return x**2    #冪的符號用**(兩個星號表示)
result = get_Square(5)
print(result)

裡的result = get_Square(5) 就是呼叫了函式get_Square(),然後把返回的值賦給了變數result;那麼我們發現要呼叫一個函式,需要知道函式的名稱

傳入的引數

其實Python內建了很多有用的函式,我們可以直接呼叫:

##coding:utf-8
#python 3.5.1
print('abs(-10):',abs(-10))
print('min(1,2,-5,10):',min(1,2,-5,10))

#結果

abs(-10): 10

min(1,2,-5,10): -5

如下是 M_f_def.py 中的程式碼:

#coding:utf-8
#python3.5.1
import requests

from bs4 import BeautifulSoup


headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
} #定義函式(傳入引數url) def get_Soup(url): response = requests.get(url,headers = headers,timeout = 120) response.encoding = 'utf-8' res = response.text soup = BeautifulSoup(res,'html.parser') return soup #返回soup #呼叫函式

建立一個檔案M_f_call.py  ,開始匯入.py檔案,再呼叫函式,如下

#coding:utf-8
#python 3.5.1
import 
M_function.M_f_def as Fuc import Calcs.calc1 as calcu #這裡呼叫了.calc1.py檔案,結合下面的PS看 soup = Fuc.get_Soup(url = 'http://blog.csdn.net/weixin_39701039/article/details/79563012') print(soup)

#結果:


PS:注意M_f_call.py 檔案要和 M_function在同一個資料夾下(不一定在M_function裡),如下圖:


望有所幫助,望採納!!

相關推薦

To watchneed to Move on

Python3.5 函式的呼叫望共同進步轉載請註明地址:http://blog.csdn.net/weixin_39701039/article/details/79567006寫函式的定義的時候其實已經呼叫了函式,如#coding:utf-8 #python 3.5.1 d

C語言編碼轉換gb2312 to utf8utf8 to gb2312 代碼GCC編譯支持Windows、Linux

inb style fine mem amp blog linu print from 編譯:gcc -o f.exe f.c -liconv #include <stdio.h> #include <stdlib.h> #include <

if you want to fly,you need to walk step by step

http://blog.csdn.net/panxueji/article/details/9949841 來源(來源不明-轉載請標明此連結)一、IO流的三種分類方式:1.按照流向來分:輸入流:只能從中讀取位元組資料,不能向其寫出資料輸出流:只能向其寫入位元組資料,不能從中讀

Spring Boot 利用插件構造QueryDSL語句時報錯:You need to run build with JDK or have tools.jar on the classpath.If this occur....

cli roc ini文件 The 解決 tps proc 自己 沒有 You need to run build with JDK or have tools.jar on the classpath.If this occures during eclipse buil

在Ubuntu上安裝sublime 3 how to install sublime 3 text on Ubuntu 18.04

sta ans tran repos date 8.0 ensure pos http apt Install the GPG key: wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo

按照官網寫的第一個APP出現了You need to use a Theme.AppCompat theme (or descendant) with this activity問題

這是我第一次根據Android官網指導寫的APP,連結如下: 每一步都嚴格參照了官網指導,一步一步敲程式碼、執行,結果報瞭如下錯誤: 10-08 18:08:40.878 18503 18503 E AndroidRuntime: Caused by: java.la

Neon and corporate dystopias: why does cyberpunk refuse to move on?

The future has looked the same for almost four decades. A skyline of densely packed skyscrapers, corporate logos lighting the night sky, proclaiming owners

Three iPhones and a watch: Everything You Need to Know about Apple’s Sept 12 Event

Three iPhones and a watch: Everything You Need to Know about Apple’s Sept 12 EventCredit: EngadgetIt looks like the rumours were right on the money.On Wedn

How we screwed things up on Product Hunt and the #1 rule you need to follow to avoid it

How we screwed things up on Product Hunt and the #1 rule you need to follow to avoid itBeing on Product Hunt front page is a huge deal for startups, especi

How Much Money Do You Need to Move the Bitcoin Market?

How Much Money Do You Need to Move the Bitcoin Market?Whale Science 

python出現coercing to unicode need string or buffer nonetype found python 錯誤的解決

這是由於型別不對,而導致的         1  我是用 “a”+b這個時候產生的錯誤,         2  這是由於 ,在 python中 +號是針對兩個型別相同的變數,而在上的語句中,python不知道 b這個變數的型別二導致的錯誤(這一點和java很不一樣),

MySQL不能刪除外來鍵抱錯Error on rename of './ruler/test2child' to './ruler/#sql2-298-92' (errno: 152)

曾經這是MySQL的一個bug,但是現在只是MySQL的一個不友好的地方。 例子如下: mysql> ALTER TABLE ruler.test2child DROP FOREIGN KEY test; ERROR 1025 : Error on rename of './ruler/t

I need to reset the administrator password on a Windows Server instance in Amazon EC2

2.    From the Amazon EC2 console, in the navigation pane expand Systems Manager Services, and then choose Run Command. 3.    Choose

Why You Need to Put Your Tax Registration Number on All Accounts

If AWS accepts TRNs from your country on the Tax Settings page, adding a TRN, business legal name, and business legal address to each of these

thinkphp Call to a member function move() on a non-object

報錯:Call to a member function move() on a non-object 解決:加上接受引數 $file = request()->file('file');

webstorm 打開後 一直停留在scanning files to index....或跳出內存不夠的提示框

tez jsb code ont 點擊 pst == sta fcm 用著有時會這樣,超級卡, 網上搜了下,原來如此,記錄下,免得忘了。 ------------------------- 說明: 在npm install 後,會出現Scanning files to in

窩上課不聽how to learn C language easily(1)

程序 簡單 小數 如果 如何 好處 class 數組 指針 C language 學習心得 附:為啥起這麽霸氣側漏,招大神們鄙視的標題,正如我在《C language》隨筆的介紹中寫的,這是一個寫個妹紙們看的C language的文章。沒錯!!寫這篇文章的靈感也來自於上周C

check whether the subset(no need to be consective) and be sum of X

subsets [] bool else true ret code art size #include "stdafx.h" bool isSubsetSum(int set[], int n, int sum) { bool sumOfSubSet[100][1

The 4 Most Important Things You Need to Do

screen any bsp take make chan head som who   We live in an age where food which used to take us hours to obtain can be delivered to your

windows安裝xampp時出現unable to realloc xxxxxxxx bytes

操作 white ble 微軟 io性能 mic clas 微軟雅黑 ica 摘錄自:http://blog.csdn.net/lz610756247/article/details/70842166               Windows虛擬內存的設置 問題描述:由於