python 掌握之路(一)

本文通过多个实例介绍Python的基础编程知识,包括打印语句、循环结构、字符串操作、数学运算、变量作用范围、ASCII与Unicode编码转换等核心概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# use case 1: the first python program
print "hello world";

# use case 2: the second python program : use keyword :for
for i in range(10):
    print str(i)+"hello worldww";
print "add";

# use case 3: the second python program : use keyword for (2. write mult lines)
for i in range(10):
    print str(i)+"hello worldww";
    print "add";

# use case 4: multLine annotation
'''
print "multline ";

'''

#use case 5: pint a string of string
print "hello world " , "secod string " ,"third string ";

#use case 6 : print calulate
print '3+5 =' , 3+5 ;

#use case 7: input a string
'''
name = raw_input();
print 'the name is value :',name ;

#use case 8: input a string with information
name = raw_input('please input a name');
print 'the name is value :',name ;
'''
#use case 9: print absolute value of a integer (use the key word of if )
a=100
if a>=0:
    print a;
else:
    print -a;


#use case 10: print ' or ""
print '\"i\'m enjoy pthon \"';


#use case 11 : use +
x = 100;
x = x+300;
print x;
x ="a string";
print x;


#use case 12: about int and float

print 10/3;
print 10.0/3;
print 10%3;
print 10.0%3;


#use case 13: out of range of variable
b ='B';
b = 65574; # haven't out of range . good !
b = 898888888;
print b ;

#use case 14: ACSII code ,UNICODE
'''
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''

print ord('T'),chr(100) , unicode('T'), len('hello'),len(unicode('hello')),len(unicode("你好".decode('utf-8'))) , "你好";

#use case 15 , connect string
print "the nuber i want to enter is %d , the name of mine is %s"%(7 , "liujie");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值