![]() |
Python Tutorial Chapter 2 - More Python - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Python (https://sinister.ly/Forum-Python) +--- Thread: Python Tutorial Chapter 2 - More Python (/Thread-Python-Tutorial-Chapter-2-More-Python) Pages:
1
2
|
Python Tutorial Chapter 2 - More Python - MrGeek - 05-17-2013 Chapter -- > 2 :~# More python #2.1 --|Numbers|-- Python is just like powerful language such as C and java, supports 3 data types for scientific calculations. The three DATA TYPES are : 1. Integer 2. String 3. Boolean +================================================================+ #2.2 --|Variables|-- In python language, Variables needn't declared. You can call them right from where you need them! For instance Variable can be assigned by just simply typing x = 6 But in other lanugages such as C++ You have to declare variable as follows; Quote:int x;Another example Quote:>>>x = 3 First variable x is assgined integer 3 Then variable y is assgined integer 3 After that, print function is used to output the results. Now you should have grub the basics of variable ![]() +===============================================================+ 2.3# --|Functions|-- (General) Now we're going to talk about functions briefly Functions are vital in every programming lanugages. You can define your own function or use the existing function. Function is sort of like a feature, for example "pow(x,y)" is a function. Functions can help make your program more powerful and as well as making your program easier to maintain! In C++ when writing functions (I lost memory on C++ not very sure ![]() Quote:1. Definition must be first declared +==================================================================+ 2.4# --|Modules|-- (General) You may have realized the import statement above some of the programs. Eg. import math Import is a command that import the modules into the program. Modules can make program more powerful. We'll come to modules later... +==================================================================+ 2.5# --|Comments|-- If you have tried any one of programming language, you would have heard about comment definately. Every programming language has it's own style of writting comments. For example, For eg. C style comment is /* comment */ In python you just need to use sharp sign "#" Code: #!usr/bin/env python Interpreter will not execute the string/code after # sign, it knows that it's a comment, and simply skips. Commenting makes the program more readable and easier to debug. We'll go into details about writing functions in next chapter. Commonly used Functions 1.print() 2.input() / raw_input() 2.float 3.complex Example, 1, 2, 3, 4 are integers. Python do not have long integer type as C language. It's included in integer type. This might be a weakness. 6.39 and 787.6E-9 is float data type. 787.6E-9 = 787.6*10-9 It also supports complex number that are commonly used in Mathematics. Example 9+7j Now we'll deal with number operatoin. #OpNo ![]() Open up Python shell. Let's get started. Code: >>> 1+1 Because Python took it as integer. But it's not the problem anymore in python version 3. Code: >>>1.0/2.0 In this way, we can calcualte basic Arithmetic Operations, such as addition, subtruction, multiplication, and division. “+ - / *” Another one Code: >>>1%2 "%" operator is used to calculate remainder of a division. Code: >>>3**2 Code: >>>-3**2 Hexadecimal and Octal are also supported Code: >>>0xCD Code: >>>0o10 Now, we've reached the end of Chapter 2 ![]() Thanks for reading. Ref : Multiple Sources MrGeek @ HC :-> logout Python Tutorial Chapter 2 - More Python - MrGeek - 05-17-2013 Chapter -- > 2 :~# More python #2.1 --|Numbers|-- Python is just like powerful language such as C and java, supports 3 data types for scientific calculations. The three DATA TYPES are : 1. Integer 2. String 3. Boolean +================================================================+ #2.2 --|Variables|-- In python language, Variables needn't declared. You can call them right from where you need them! For instance Variable can be assigned by just simply typing x = 6 But in other lanugages such as C++ You have to declare variable as follows; Quote:int x;Another example Quote:>>>x = 3 First variable x is assgined integer 3 Then variable y is assgined integer 3 After that, print function is used to output the results. Now you should have grub the basics of variable ![]() +===============================================================+ 2.3# --|Functions|-- (General) Now we're going to talk about functions briefly Functions are vital in every programming lanugages. You can define your own function or use the existing function. Function is sort of like a feature, for example "pow(x,y)" is a function. Functions can help make your program more powerful and as well as making your program easier to maintain! In C++ when writing functions (I lost memory on C++ not very sure ![]() Quote:1. Definition must be first declared +==================================================================+ 2.4# --|Modules|-- (General) You may have realized the import statement above some of the programs. Eg. import math Import is a command that import the modules into the program. Modules can make program more powerful. We'll come to modules later... +==================================================================+ 2.5# --|Comments|-- If you have tried any one of programming language, you would have heard about comment definately. Every programming language has it's own style of writting comments. For example, For eg. C style comment is /* comment */ In python you just need to use sharp sign "#" Code: #!usr/bin/env python Interpreter will not execute the string/code after # sign, it knows that it's a comment, and simply skips. Commenting makes the program more readable and easier to debug. We'll go into details about writing functions in next chapter. Commonly used Functions 1.print() 2.input() / raw_input() 2.float 3.complex Example, 1, 2, 3, 4 are integers. Python do not have long integer type as C language. It's included in integer type. This might be a weakness. 6.39 and 787.6E-9 is float data type. 787.6E-9 = 787.6*10-9 It also supports complex number that are commonly used in Mathematics. Example 9+7j Now we'll deal with number operatoin. #OpNo ![]() Open up Python shell. Let's get started. Code: >>> 1+1 Because Python took it as integer. But it's not the problem anymore in python version 3. Code: >>>1.0/2.0 In this way, we can calcualte basic Arithmetic Operations, such as addition, subtruction, multiplication, and division. “+ - / *” Another one Code: >>>1%2 "%" operator is used to calculate remainder of a division. Code: >>>3**2 Code: >>>-3**2 Hexadecimal and Octal are also supported Code: >>>0xCD Code: >>>0o10 Now, we've reached the end of Chapter 2 ![]() Thanks for reading. Ref : Multiple Sources MrGeek @ HC :-> logout RE: Python Tutorial Chapter 2 - More Python - Deque - 05-17-2013 Hi MrGeek. Again some comments from my side. Quote:Python is just like powerful language such as C and java, supports 3 data types for scientific calculations. The three DATA TYPES are : That sounds like there are only these three data types. There are more and you mentioned some of them later. I would be more precise here. Quote:Functions are vital in every programming lanugages. No. In most programming languages, not in every programming language. Quote:1. Definiation must be first declared That doesn't make sense for a beginner, nor is it correct. There is nothing like definination or defination or definiation. If you are talking about definition and declaration you must explain the terms before you use them. No programming beginner will know what you are talking about. If you are unsure about something, you should leave it away. It is no good making tutorials if you write wrong stuff in them. Quote:Commenting makes the program more readable and easier to debug. Comments are a perfume for bad smelling code. ![]() Quote:Python do not have long integer type as C language. It's included in integer type. Why a weakness? Also: This is confusing. Python has plain integer and long integer type, see: http://docs.python.org/2/library/stdtypes.html But the plain integer in python is the same as the data type long in C. So saying it has no long integer is wrong. It actually has no equivalent to the int in C. Quote:Ref : Multiple Sources That's not really a valid way to state sources. Last but not least: What Python version is this about? 2.x is not compatible to 3.x, but it is still used more than 3.x Regards Deque RE: Python Tutorial Chapter 2 - More Python - Deque - 05-17-2013 Hi MrGeek. Again some comments from my side. Quote:Python is just like powerful language such as C and java, supports 3 data types for scientific calculations. The three DATA TYPES are : That sounds like there are only these three data types. There are more and you mentioned some of them later. I would be more precise here. Quote:Functions are vital in every programming lanugages. No. In most programming languages, not in every programming language. Quote:1. Definiation must be first declared That doesn't make sense for a beginner, nor is it correct. There is nothing like definination or defination or definiation. If you are talking about definition and declaration you must explain the terms before you use them. No programming beginner will know what you are talking about. If you are unsure about something, you should leave it away. It is no good making tutorials if you write wrong stuff in them. Quote:Commenting makes the program more readable and easier to debug. Comments are a perfume for bad smelling code. ![]() Quote:Python do not have long integer type as C language. It's included in integer type. Why a weakness? Also: This is confusing. Python has plain integer and long integer type, see: http://docs.python.org/2/library/stdtypes.html But the plain integer in python is the same as the data type long in C. So saying it has no long integer is wrong. It actually has no equivalent to the int in C. Quote:Ref : Multiple Sources That's not really a valid way to state sources. Last but not least: What Python version is this about? 2.x is not compatible to 3.x, but it is still used more than 3.x Regards Deque RE: Python Tutorial Chapter 2 - More Python - Ex094 - 05-17-2013 NIce work but I have some suggestions about your tutorial, 1) Your explanation about Functions in Python is not clear and lacks proper examples 2) You've mention under the Commonly used functions as Code: Commonly used Functions This might confuse beginners as they will think all of them are separate functions like input() and raw_input(). You should have mentioned the Input() is used in Python3.3 and raw_input() in previous version that's 2.7. I recommend you write functions about single python versions that you are using otherwise beginners are going to get confused. 3) This is just a suggestion, For me whitespaces in code makes it more readable. Your example like: Code: >>2+3 If you read other tutorials like Learn Python the Hard Way, they have too stated it's better to leave spaces so that it's more readible like: Code: >>> 2 + 3 For better example here's a simple add function: No whitespaces Code: def addition(x,y): With spacing Code: def addition(x, y): You can see the difference yourself. 4) You didn't mention anything about indentation as it's important for a language like Python, one wrong indent in a long code and a beginner is gonna have a heck of a time finding it. RE: Python Tutorial Chapter 2 - More Python - Ex094 - 05-17-2013 NIce work but I have some suggestions about your tutorial, 1) Your explanation about Functions in Python is not clear and lacks proper examples 2) You've mention under the Commonly used functions as Code: Commonly used Functions This might confuse beginners as they will think all of them are separate functions like input() and raw_input(). You should have mentioned the Input() is used in Python3.3 and raw_input() in previous version that's 2.7. I recommend you write functions about single python versions that you are using otherwise beginners are going to get confused. 3) This is just a suggestion, For me whitespaces in code makes it more readable. Your example like: Code: >>2+3 If you read other tutorials like Learn Python the Hard Way, they have too stated it's better to leave spaces so that it's more readible like: Code: >>> 2 + 3 For better example here's a simple add function: No whitespaces Code: def addition(x,y): With spacing Code: def addition(x, y): You can see the difference yourself. 4) You didn't mention anything about indentation as it's important for a language like Python, one wrong indent in a long code and a beginner is gonna have a heck of a time finding it. RE: Python Tutorial Chapter 2 - More Python - MrGeek - 05-17-2013 @Deque Firstly, I would like to thank sis ![]() I'm afraid of my thread being with no reply . Now here replies and I can empower my knowledge. Quote:That sounds like there are only these three data types. There are more and you mentioned some of them later. I would be more precise here.Yep, there are more than 3 data types , I missed the word ' in genera '. Quote:That doesn't make sense for a beginner, nor is it correct. I miss spelled. My grammar sucks. Sorry about that. Fixing it now. Quote:Also: This is confusing. Python has plain integer and long integer type, see: http://docs.python.org/2/library/stdtypes.html Well, you point me to the python2 documentation. But I see no long in python3 Documentation. I am making this to sure. Quote:What Python version is this about? 2.x is not compatible to 3.x, but it is still used more than 3.xI am comparing python3 with python2 ![]() And Thanks again for reading. @Ex094 Thanks bro , you guys are always read my threads carefully ![]() I am glad to see that. Quote:1) Your explanation about Functions in Python is not clear and lacks proper examplesI already said I will explain more about them in later chaps. Quote:This might confuse beginners as they will think all of them are separate functions like input() and raw_input(). You should have mentioned the Input() is used in Python3.3 and raw_input() in previous version that's 2.7. I recommend you write functions about single python versions that you are using otherwise beginners are going to get confused.You are right! I have responsibility for not explaining input vs raw_input & there is no raw_input in python3 Quote:4) You didn't mention anything about indentation as it's important for a language like Python, one wrong indent in a long code and a beginner is gonna have a heck of a time finding it.You are right again! I missed that part. "Single-Quoted Strings and Escaping Quotes" Also , writing a programming post is more difficult than a hacking post. Regards Mr.Geek RE: Python Tutorial Chapter 2 - More Python - MrGeek - 05-17-2013 @Deque Firstly, I would like to thank sis ![]() I'm afraid of my thread being with no reply . Now here replies and I can empower my knowledge. Quote:That sounds like there are only these three data types. There are more and you mentioned some of them later. I would be more precise here.Yep, there are more than 3 data types , I missed the word ' in genera '. Quote:That doesn't make sense for a beginner, nor is it correct. I miss spelled. My grammar sucks. Sorry about that. Fixing it now. Quote:Also: This is confusing. Python has plain integer and long integer type, see: http://docs.python.org/2/library/stdtypes.html Well, you point me to the python2 documentation. But I see no long in python3 Documentation. I am making this to sure. Quote:What Python version is this about? 2.x is not compatible to 3.x, but it is still used more than 3.xI am comparing python3 with python2 ![]() And Thanks again for reading. @Ex094 Thanks bro , you guys are always read my threads carefully ![]() I am glad to see that. Quote:1) Your explanation about Functions in Python is not clear and lacks proper examplesI already said I will explain more about them in later chaps. Quote:This might confuse beginners as they will think all of them are separate functions like input() and raw_input(). You should have mentioned the Input() is used in Python3.3 and raw_input() in previous version that's 2.7. I recommend you write functions about single python versions that you are using otherwise beginners are going to get confused.You are right! I have responsibility for not explaining input vs raw_input & there is no raw_input in python3 Quote:4) You didn't mention anything about indentation as it's important for a language like Python, one wrong indent in a long code and a beginner is gonna have a heck of a time finding it.You are right again! I missed that part. "Single-Quoted Strings and Escaping Quotes" Also , writing a programming post is more difficult than a hacking post. Regards Mr.Geek RE: Python Tutorial Chapter 2 - More Python - MrGeek - 05-17-2013 By the way , I'm confused about choosing python27 or 33 as my primary. I've already developed a tool with python27. But now currently reading both 2 and 3. If I installed 33 I cannot run sqlmap or similar written in 27. Any suggestions?? RE: Python Tutorial Chapter 2 - More Python - MrGeek - 05-17-2013 By the way , I'm confused about choosing python27 or 33 as my primary. I've already developed a tool with python27. But now currently reading both 2 and 3. If I installed 33 I cannot run sqlmap or similar written in 27. Any suggestions?? |