99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀Python字符串拼接六種方法介紹
Python字符串拼接六種方法介紹
2018-02-16
收藏

Python字符串拼接六種方法介紹

Python字符串拼接的6種方法:
1.加號
第一種,有編程經(jīng)驗的人,估計都知道很多語言里面是用加號連接兩個字符串,Python里面也是如此直接用“+”來連接兩個字符串;    
print 'Python' + 'Tab'
結(jié)果:    
PythonTab
2.逗號
第二種比較特殊,使用逗號連接兩個字符串,如果兩個字符串用“逗號”隔開,那么這兩個字符串將被連接,但是,字符串之間會多出一個空格;    
print 'Python','Tab'
結(jié)果:    
Python Tab
3.直接連接
第三種也是,ython獨有的,只要把兩個字符串放在一起,中間有空白或者沒有空白,兩個字符串將自動連接為一個字符串;    
print 'Python''Tab'
結(jié)果:    
PythonTab    
print 'Python'  'Tab'
結(jié)果:    
PythonTab
4.格式化
第四種功能比較強大,借鑒了C語言中printf函數(shù)的功能,如果你有C語言基礎,看下文檔就知道了。這種方式用符號“%”連接一個字符串和一組變量,字符串中的特殊標記會被自動用右邊變量組中的變量替換:    
print '%s %s'%('Python', 'Tab')
結(jié)果:    
Python Tab
第五種join
就屬于技巧了,利用字符串的函數(shù)join。這個函數(shù)接受一個列表,然后用字符串依次連接列表中每一個元素:    
str_list = ['Python', 'Tab']
a = ''
print a.join(str_list)
結(jié)果:    
PythonTab
第六種 多行字符串拼接()    
s = ('select *'
   'from atable'
   'where id=888')
print s, type(s)
 
#輸出
select *from atablewhere id=888 <type 'str'>
python遇到未閉合的小括號,自動將多行拼接為一行,相比三個引號和換行符,這種方式不會把換行符、前導空格當作字符。
總結(jié)
以上就是本文關(guān)于Python字符串拼接六種方法介紹的全部內(nèi)容,希望對大家有所幫助。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }