Python 3
#!/usr/bin/python3
1. Define classes
class Dog:
def bark(self):
print('Gau Gau Gau!')
def swim(self):
print('Swims like a dog.')
def main():
nauvang = Dog()
nauvang.bark()
nauvang.swim()
if __name__ == "__main__": main()
2. Define and use a function
2.1
def main():
testfunc()
def testfunc():
print('This is a test function')
if __name__ == "__main__": main()
2.2
def main():
print("This is the functions.py file.")
for i in range(25):
print(i, end = ' ')
if __name__ == "__main__": main()
3. Work with regular expressions
import re
def main():
fh = open('toys.txt')
for line in fh:
if re.search('(Leg|g)o', line):
print(line, end='')
if __name__ == "__main__": main()
4. Work with files
def main():
f = open('readme.txt')
for line in f:
print(line, end = '')
if __name__ == "__main__": main()
Friday, January 9, 2015
Subscribe to:
Posts (Atom)
Mounting USB drives in Windows Subsystem for Linux
Windows Subsystem for Linux can use (mount): SD card USB drives CD drives (CDFS) Network drives UNC paths Local storage / drives Drives form...
-
I. Five different ways to answer a question II. Use SOLO strategies to explain our thinking and reasoning III. SOLO Taxono...
-
Learning levels 1, 2, and 3 Learning levels 4, 5, and 6 References http://www.cccs.edu/Docs/Foundation/SUN/QUESTIONS%20FOR%20TH...