VS2013中Python學習筆記[基礎入門]


前言  

        在上一節中簡單的介紹了在VS2013中如何進行開發Hello World,在VS2013中進行搭建了環境http://www.cnblogs.com/aehyok/p/3986168.html。本節主要來簡單的學習一下關於Python的基礎。

Python基礎入門  

1、打印一個字符串Hello World.

print('Hello World')

 

2、打印一個路徑

print('C:\aehyok\aehyok')

可以發現\a發生了轉義。如果不想發生轉義,只需要在字符串前添加一個r

print(r'C:\aehyok\aehyok')

 

3、字符串拼接和字符串重復次數

print('str'+'ing','aehyok'*3)

 

4、字符串兩種索引方式,從左到右索引從0開始,從右到左索引從-1開始。

word='aehyok'
print(word[0],word[5])
print(word[-1],word[-5])

 

5、對字符串進行切分:用冒號分隔兩個索引,形式為變量[頭下標:尾下標]。截取的范圍是前閉后開的

cat='aehyok'
print(cat[3:])
print(cat[3:6])
print(cat[:-1])
print(cat[-1])

 

6、獲取鍵入字符串,並打印字符串以及字符串長度和類型

object = input('Enter an ojbect : ')
print("Get anlu integer is",object,type(object),len(object))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM