Python : The Beginning - Hallo sahabat Computer Programmer Medical Coding, Pada Artikel yang anda baca kali ini dengan judul Python : The Beginning, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan
Artikel Beginners,
Artikel Python, yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.
Judul : Python : The Beginning
link : Python : The Beginning
Artikel yang anda baca saat ini Python : The Beginning dengan alamat link https://idkingcode.blogspot.com/2016/08/python-beginning.html
Judul : Python : The Beginning
link : Python : The Beginning
Python : The Beginning
This is the last entry in basic Python! I will be posting my review in the post after this, and then we will begin GUI programming with Tkinter, a real-world application!Dictionaries Pt. 2
predef = [1, 2, 3, 4]predeflist = {’predef’: predef}print predeflist
This sets a predefined key and value.Modules
Modules are scripts and such that you can “import” into the program. They give new functions. I will find and review three modules.
Module #1: The
math
Module
import mathx = -223.55print “Original Number:”, xprint “Absolute Value:”, math.fabs(x)print “Smallest integer value greater than or equal to original:”, math.ceil(x)print math.floor(x)
The module ‘math’ is imported. ‘x’ is defined as ‘-223.55′. ‘fabs(x)’ is a function of the module which finds the absolute value of a number. ceil(x) finds the smallest integer value greater than or equal to original.
Module #2: The
operator
Module
import operatorx = -223.55y = 5print operator.neg(x)print operator.add(x, y)print operator.sub(x, y)
‘neg(x)’ negates ‘x’. ‘add(x, y)’ adds x and y. ’sub(x, y)’ subtracts ‘y’ from ‘x’.
Module #3: The
time
Module
import timeprint time.ctime()
‘ctime’ prints the current time.
Info about modules in the standard library can be found in the Standard Library Reference. Information about most of the modules known in the world can be found in Vaults of Parnassus: Python Resources.
When running a script that imports a module, never name the script the same name as the module, because then the ‘import’ command will try to read itself.
Finally, the last basic lesson of all time, file IO.File IO
out_file = open(”test.txt”, “w”)out_file.write(”Hello World\n(on your actual HD!)”)out_file.close()
in_file = open(”test.txt”, “r”)text = in_file.read()in_file.close()
print text
This program creates a file called ‘test.txt’ in your user folder in ‘out_file = open(”test.txt”, “w”)’
Then, it writes content in the file with the command ‘out_file.write(”Hello World\n(on your actual HD!)”)’ The ‘/n’ acts as a space. ‘out_file.close()’ closes the file.
‘in_file = open(”test.txt”, “r”)’ opens the file for reading. ‘text = in_file.read()’ declares the inside content as the variable ‘text’. ‘in_file.close()’ closes the file. ‘text’ is printed.
So congrats, you did it! You learned all your basic Python! If my blog has helped you in any significant way, email me a testimonial at info [at] python-tutorials [dot] com. I just need to write my review of Python as a nonprogrammer and post it, then we will begin GUI Programming! I also need to index the tutorials on a single page.
This sets a predefined key and value.Modules
Modules are scripts and such that you can “import” into the program. They give new functions. I will find and review three modules.
Module #1: The
math
Module
import mathx = -223.55print “Original Number:”, xprint “Absolute Value:”, math.fabs(x)print “Smallest integer value greater than or equal to original:”, math.ceil(x)print math.floor(x)
The module ‘math’ is imported. ‘x’ is defined as ‘-223.55′. ‘fabs(x)’ is a function of the module which finds the absolute value of a number. ceil(x) finds the smallest integer value greater than or equal to original.
Module #2: The
operator
Module
import operatorx = -223.55y = 5print operator.neg(x)print operator.add(x, y)print operator.sub(x, y)
‘neg(x)’ negates ‘x’. ‘add(x, y)’ adds x and y. ’sub(x, y)’ subtracts ‘y’ from ‘x’.
Module #3: The
time
Module
import timeprint time.ctime()
‘ctime’ prints the current time.
Info about modules in the standard library can be found in the Standard Library Reference. Information about most of the modules known in the world can be found in Vaults of Parnassus: Python Resources.
When running a script that imports a module, never name the script the same name as the module, because then the ‘import’ command will try to read itself.
Finally, the last basic lesson of all time, file IO.File IO
out_file = open(”test.txt”, “w”)out_file.write(”Hello World\n(on your actual HD!)”)out_file.close()
in_file = open(”test.txt”, “r”)text = in_file.read()in_file.close()
print text
This program creates a file called ‘test.txt’ in your user folder in ‘out_file = open(”test.txt”, “w”)’
Then, it writes content in the file with the command ‘out_file.write(”Hello World\n(on your actual HD!)”)’ The ‘/n’ acts as a space. ‘out_file.close()’ closes the file.
‘in_file = open(”test.txt”, “r”)’ opens the file for reading. ‘text = in_file.read()’ declares the inside content as the variable ‘text’. ‘in_file.close()’ closes the file. ‘text’ is printed.
So congrats, you did it! You learned all your basic Python! If my blog has helped you in any significant way, email me a testimonial at info [at] python-tutorials [dot] com. I just need to write my review of Python as a nonprogrammer and post it, then we will begin GUI Programming! I also need to index the tutorials on a single page.
Boolean expressions are expressions that have the values ‘True’ or ‘False’ as results.
Type in the following script:
a = 1b = 2print 1, a == 1print 2, a == 2print 3, a == 1 and b == 2print 4, a == 3 and b == 3print 5, not a == 123456 and b == 2print 6, a == 1 or b == 2000print 7, not (a == 100 and b == -57)
The result:
1 True2 False3 True4 False5 True6 True7 True
In this program, two variables, ‘a’ and ‘b’, are defined as ‘1′ and ‘2′ respectively. Then the program prints if an expression is true or not. For instance, ‘print 1, a == 1′ prints out ‘True’, because ‘a’ is equal to ‘1′. ‘print 2, a == 2′ prints out ‘False’ because ‘a’ is not equal to ‘2′. The ‘and’ operator checks if two expressions are both true. The ‘not’ operator checks if an expression is not true. With ‘or’, one of the expressions can be true. Finally, in the last one, brackets symbolize that both expressions must be false to be true.
Some more interesting Boolean Expressions:
print ‘1′ == (’1′ or ‘2′)
If you put this in IDLE, it will return as “true”, because Python checks the first value “1″, and since it’s true, due to it’s laziness, it assumes that the entire operator is true.
print ‘2′ == (’1′ or ‘2′)
Python declares this false because since “1″ isn’t equal to “2″, it just assumes that it’s false.
print ‘1′ == (’1′ and ‘2′)
Python declares this false because with an “and” operator, it checks the first variable, and whatever it turns out to be, it checks the second one and since 1 != 2, it is declared false.
print ‘2′ == (’1′ and ‘2′)
The first one is false, but it goes to the second one. Since the second one is true, Python declares the argument to be true.Challenge: Using what you learned, create a program where you have to enter both a username and a password. The program will say “You are correct” or “You are Incorrect.” The person will get five tries. Also, to get the usual reward, you must use the “and” operator at least once.
Type in the following script:
a = 1b = 2print 1, a == 1print 2, a == 2print 3, a == 1 and b == 2print 4, a == 3 and b == 3print 5, not a == 123456 and b == 2print 6, a == 1 or b == 2000print 7, not (a == 100 and b == -57)
The result:
1 True2 False3 True4 False5 True6 True7 True
In this program, two variables, ‘a’ and ‘b’, are defined as ‘1′ and ‘2′ respectively. Then the program prints if an expression is true or not. For instance, ‘print 1, a == 1′ prints out ‘True’, because ‘a’ is equal to ‘1′. ‘print 2, a == 2′ prints out ‘False’ because ‘a’ is not equal to ‘2′. The ‘and’ operator checks if two expressions are both true. The ‘not’ operator checks if an expression is not true. With ‘or’, one of the expressions can be true. Finally, in the last one, brackets symbolize that both expressions must be false to be true.
Some more interesting Boolean Expressions:
print ‘1′ == (’1′ or ‘2′)
If you put this in IDLE, it will return as “true”, because Python checks the first value “1″, and since it’s true, due to it’s laziness, it assumes that the entire operator is true.
print ‘2′ == (’1′ or ‘2′)
Python declares this false because since “1″ isn’t equal to “2″, it just assumes that it’s false.
print ‘1′ == (’1′ and ‘2′)
Python declares this false because with an “and” operator, it checks the first variable, and whatever it turns out to be, it checks the second one and since 1 != 2, it is declared false.
print ‘2′ == (’1′ and ‘2′)
The first one is false, but it goes to the second one. Since the second one is true, Python declares the argument to be true.Challenge: Using what you learned, create a program where you have to enter both a username and a password. The program will say “You are correct” or “You are Incorrect.” The person will get five tries. Also, to get the usual reward, you must use the “and” operator at least once.
Demikianlah Artikel : Python : The Beginning
Semoga artikel Python : The Beginning ini, bisa memberi manfaat untuk anda semua dan jangan bosan untuk datang kembali mengunjungi blog ini. Baiklah, sampai jumpa di postingan artikel lainnya.
Artikel yang anda baca saat ini Python : The Beginning dengan alamat link https://idkingcode.blogspot.com/2016/08/python-beginning.html
Python : The Beginning
4/
5
Oleh
Unknown
