1. command line arguments in python
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
2. vowel or consonent
str="asadiougjhasgdkjhgfkhj"
li=['a','e','i','o','u']
for var in str:
if var in li:
print "%svowel"%var
else:
print "%snot vowel"%var
3.file write
fp=open("welcome.txt",'wb')
fp.write("welcome to python");
4. line count character count in a file
fp=open("sample.txt")
count=0
c=0
for line in fp:
for ch in line:
c=c+1
count=count+1
print('line count',count)
print("char count",c)
5. class program in python
class abc:
x=0
def inc(self):
self.x=self.x+1
print("so far",self.x)
an=abc()
an.inc()
an.inc()
No comments:
Post a Comment