# fIn = file (in) fOut = file (out) fIn = open("file.txt","r") ## opening a file for read. ## read line by line for line in fIn: print line ## file name is fIn ## how to turn string to int func. or float myInt = int(myString) ## string to Floating point / myFloat = float(my String) ## how to trap Convertion errors try: myInt = int(myString) except: print "Error" ## write to consle print ## using else, if, elif statments if myInt > 0: print "positve" elif myInt < 0: print "negitve" else myInt = 0: print "Zero" ## creating a list Data type and add value ## sqaure brackets = lists myList = [] myList.append(3) ## Fuctions that use list as arguments # max, min, sum, count ## how to use a dictionary data type myDict = dict() myDict["E12345"] = myInt for key in myDict: print myDict[key] ## key referance the value fIn = open("file.txt" , "w") ## how to write to the open file fIn.write("hello world") ## how to close the file thats open fIn.close()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question