pythonÓï·¨½éÉÜ
1.1. Óï·¨
1.1.1. if
>>> x=int(raw_input("please enter an integer:"))
please enter an integer:-8
>>> if x<0:
... print 'negative'
... elif x==0:
... print 'zero'
... else:
... print 'positive'
...
negative
ÕâÀïÓм¸¸ö֪ʶµãÐèÒªÌáÐÑ£º
1¡£ºÍshellÖÐifÓï¾äµÄÇø±ð
ÎÒÃÇÀ´»Ø¹ËÒ»ÏÂshellÖеÄifÓï¾ä¡£
shellÖÐifÓï¾äµÄ½á¹¹ÊÇ£º
if ±í´ïʽ
then ÃüÁî±í
[else]
fi
¾Ù¸ö¼òµ¥µÄÀý×Ó£ºifsingle
#!/bin/bash
#filename:ifsingle
echo "please enter the first string:"
read word1
echo "please enter the second string:"
read word2
echo "_______________"
if test $word1 = $word2 ÕâÀï×¢Òâ$word1ºÍ$word2Ö®¼äµÄµÈºÅǰºó±ØÐëÓпոñ£¬²»È»¾Í±ä³ÉÁ˸³ÖµÓï¾ä£¬³ÌÐòµÄ¹¦ÄܾÍÌåÏÖ²»³öÀ´ÁË¡£
then
echo " the first string is equal to the second string"
fi
echo "the program has finished"
²¢ÇÒifÓï¾ä¿ÉÒÔÎÞÏÞ²ãµÄǶÌ×ÔÚÆäËûifÓï¾äÖС£
pythonÖеÄÊÇÒ»¸öif£¬elif,elseÓï¾äʵÏÖ¶à·ÅжÏ
ÎÒÃÇͬÑù¾ÙÒ»¸öÏàËÆµÄÀý×Ó£º
ʹÓÃvi±à¼Æ÷½øÐб༣º
#!/bin/bash
#filename:ifelif
echo "please enter the first argu:"
read str1 z×¢ÒâÕâÀïÇв»ÒªÊ¹ÓÃ$1£¬ÒòΪ$1ÊÇÖ¸³ýÁ˳ÌÐòÃûµÄµÚÒ»¸ö²ÎÊý
echo "please enter the second argu:"
read str2
echo "please enter the third argu:"
read str3
if test $str1 = $str2 -a $str2 = $str3 test ÓÃ[ ]ÊÇtestµÄÓï·¨£¬ÐèÒªÓÃ-a±íʾÂß¼Ó룬µ±È»test Ò²¿ÉÒÔ²»ÊµÓÃ[]
then
echo "the three argu are same"
elif test $str1 = $str2
then
echo "the first argu is equal to the second argu"
elif test $str2 = $str3
then
echo "the second argu is equal to the third argu"
elif test $str1 = $str3
then
echo "the third argu is equal to the first argu"
else
echo " they are different"
fi
2
Ïà¹ØÎĵµ£º
import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''
#print ('this is init funnction') ......
1¡¢ÔÚPythonÖÐ×î»ù±¾µÄÊý¾Ý½á¹¹ÊÇÐòÁУ¨sequence£©£¬ÐòÁÐÖеÄÿ¸öÔªËØ±»·ÖÅäÒ»¸öÊý×Ö——ÔªËØµÄλÖã¬Ò²½ÐË÷Òý¡£µÚÒ»¸öË÷ÒýÊÇ 0£¬µÚ¶þ¸öË÷ÒýÊÇ1£¬Èç´ËµÝÍÆ¡£ÐòÁÐÖеÄ×îºóÒ»¸öÌõÄ¿±»±ê¼ÇΪ-1£¬µ¹ÊýµÚ¶þÊÇ-2£¬Èç´ËµÝÍÆ¡£
2¡¢ÐòÁУºeg:edward = ['Edward Gumby', 42]£¬ÐòÁÐÒ²Äܰüº¬ÆäËûµÄÐòÁС£Ð ......
×î½üÔÚÑжÁPythonÔ´ÂëÆÊÎöÒ»Ê飬´ËÊéÏ൱²»´í£¬Èç¹û×Ô¼º³å¶¯µÄÈ¥·ÖÎöPythonÔ´Âë¿ÉÄܻᵽ´¦Åö“±Ç”£¬¿´µ½´ËÊéʱÊÇ09Ä꣬ÄÇʱΪÁËÑо¿ÄÚ´æ»úÖÆ²Å·¢ÏÖÓÐÕâôһ±¾Ê飬µ«Êǹ¤×÷̫棬¸ù±¾Ã»Ê±¼äÈ¥·ÖÎöÔ´Â룬µ½ÁË2010Ä꣬ÕâÊǷdz£ÓÐÉîÖØÒâÒåµÄÒ»Ä꣬ËùÒÔÕâÒ»ÄêÒ»¶¨Òª±È֮ǰ×öµÄ»¹Òª¸¶³ö¸ü¶à£¬ÒªÏë³ÉΪ¼¼Êõ¶¥¼â¾Í±ØÐëÑÐ ......
(1).µ±"print os.path.dirname(__file__)"ËùÔڽű¾ÊÇÒÔÍêÕû·¾¶±»ÔËÐеģ¬ ÄÇô½«Êä³ö¸Ã½Å±¾ËùÔÚµÄÍêÕû·¾¶£¬±ÈÈ磺
python d:\pythonSrc\test\test.py
&nb ......
PythonÖ§³Öascii×Ö·û´®£¬unicode×Ö·û´®£¬ÒÔ¼°¸÷ÖÖ×Ö·û¼¯£¬ÄÇôËüÃǵ½µ×¸÷ÊÇʲô¸ÅÄÏ໥֮¼ä´æÔÚºÎÖÖ¹ØÏµÄØ£¿
ÔÚPythonÖУ¬ascii×Ö·û´®£¬¼´strÀàÐ͵ÄÖµ£¬¿ÉÄÜÓÃÀ´±íʾÈÎÒâµÄÒ»¿é´æ´¢¿Õ¼ä£¬ÄÇôҲ¾ÍÊÇ˵£¬Õâ¸ö×Ö·û´®ÄÚ²¿¿ÉÒÔÊÇÈκÎÖµ£¬ÀýÈ磺¿É¼û×Ö·û×é³ÉµÄ×Ö·û´®£¬»òÕßÒ»¶Î¶þ½øÖÆÊý¾ÝµÈ¡£unicode×Ö·û´®£¬¼´unicodeÀàÐ굀 ......