பைத்தான் ஆனது  Guido van Rossum  என்பவரால் 1990 களில்
உருவாக்கப்பட்டது. அதன் லேட்டெஸ்ட் வெர்சன் 3.7.1 ஆகும்.பைத்தான்
ஒரு கம்பைல்டு மொழி கிடையாது. இன்டெர்பிரட்டெட் ஆகும்.அதனால் ஒவ்வொரு வரியாக
சரிபார்க்கப் படும்.இந்த கட்டுரையில் பைத்தானின் அடிப்படைகள் குறித்துக் காண்போம்.
சான்று நிரல்.
இந்த நிரலில் hello world என்பதை எவ்வாறு காண்பிப்பது என்று
காண்போம்.
| 
# Python code for "Hello World"  
# nothing else to type...see how simple is the syntax.  
print("Hello
  World")        | 
ஒரே வரியில் எளிதாக எழுதப் பட்டிருப்பதைக் காணுங்கள். இதே நிரலை c,c++,java, c# மொழிகளில் எழுதுவதற்கு எத்தனை வரிகள் வேண்டும் என்பதை நாம் அறிவோம்.
பைத்தான் ஆனது “{ }” என்கின்ற பிரேஸ்
கொண்டு அதன் scope ஆனது சார்ந்திருப்பதில்லை. அதற்கு பதில் அஇன்டெண்டேசன் கொண்டு
நிர்ணயிக்கப் படுகின்றது.
வேரியபிள்கள் மற்றும் டேட்டாஸ்ட்ரக்சர்.
C,c++,java போல் வேரியபிள்களை அறிவிக்கத் தேவையில்லை. அதற்குப்
பதில் ஒரு வேரியளுக்கு எந்த டைப் டேட்டாவை மதிப்பிருத்துகின்றோமோ அந்த டைப்பாக
வேரியபிள் எடுத்துக் கொள்ளப்படும் 
| 
# Python program to declare variables  
myNumber = 3 
print(myNumber)  
myNumber2 = 4.5 
print(myNumber2)
   
myNumber
  ="helloworld" 
print(myNumber)
   | 
வெளியீடு:
3
4.5
helloworld
 எனவே ஒரு
வேரியபிளை உருவாக்கி அதற்கு மதிப்பிருத்தி அதை 
print ஃபங்க்சன் கொண்டு வெளியீடு செய்ய வேண்டும். பைத்தான்
list,dictionary, tuple மற்றும் set என்று நான்கு வகையான data structure
கொண்டுள்ளது. 
List என்பது அடிப்படை டேட்டா ஸ்ட்ரக்சர்
ஆகும். இது  mutable ஆகும். ஒரு லிஸ்டை
உருவாக்கி பின் எத்தனை வகையான டேட்டாக்களையும் நாம் சேர்த்துக் கொள்ளலாம்.
| 
# Python
  program to illustrate list   
#
  creates a empty list  
nums = []   
#
  appending data in list  
nums.append(21)
   
nums.append(40.5)
   
nums.append("String")
   
print(nums)
   | 
Output: 
[21, 40.5, String]
Comments:
# என்பது ஒற்றை
வரி காமெண்டாக பயன்படுகின்றது
"""
this is a comment """ என்பது மல்டி லைன் காமெண்டாக
பயன்படுகின்றது.
இன்புட்
மற்றும் அவுட்புட்
பின் வரும் நிரலில் ஒரு ஸ்ட்ரிங்க் இன்புட் வாங்கப்பட்டு அது
வெளியீடு செய்யப்பட்டுள்ளது.
| 
# Python
  program to illustrate  
#
  getting input from user  
name = input("Enter
  your name: ")  
# user
  entered the name 'harssh'  
print("hello",
  name)  | 
வெளியீடு:
hello harssh   
| 
#
  Python3 program to get input from user  
#
  accepting integer from the user  
num1 = int(input("Enter
  num1: "))   
num2 = int(input("Enter
  num2: "))  
num3 = num1 * num2  
print("Product
  is: ", num3)  | 
வெளியீடு:
Enter num1: 8 Enter
num2: 6 ('Product is: ', 48)
Selection
செலெக்சன் if மற்றும் elif கீவேர்டு கொண்டு
மேற்கொள்ளப்படுகின்றது.
| 
# Python
  program to illustrate  
#
  selection statement  
num1 = 34 
if(num1>12):
   
    print("Num1
  is good")  
elif(num1>35):
   
    print("Num2
  is not gooooo....")  
else:  
    print("Num2
  is great")  | 
வெளியீடு:
Num1 is good
Functions 
ஓரு ஃபங்க்சன் ஆனது ஒரு கட்டளை வரிகளின் தொகுப்பாகும். இது
குறிப்பிட்ட செயல்களைச் செய்ய பயன்படுகின்றது.ஒரு தடவை எழுதிக் கொண்டு எத்தனை முறை
வேண்டுமானாலும் அழைத்துக் கொள்ளலாம்.
 Syntax:
def
function-name(arguments):
            #function body
| 
# Python
  program to illustrate  
#
  functions  
def hello():  
    print("hello")
   
    print("hello
  again")  
hello()  
#
  calling function  
hello()               
   | 
வெளியீடு:
hello
hello again
hello
hello again
பொதுவாக நிரலாக்க மொழிகளில் நிரல் main ஃபங்க்சனில் இருந்தே
இயங்கத் தொடங்கும். பைத்தானில் எவ்வாறு main ஃபங்க்சன் உருவாக்குவது என்று
காண்போம்.
| 
# Python
  program to illustrate   
#
  function with main  
def getInteger():  
    result
  =
  int(input("Enter
  integer: "))  
    return result  
def Main():  
    print("Started")
   
#
  calling the getInteger function and   
#
  storing its returned value in the output variable  
    output
  =
  getInteger()     
   
    print(output)
   
# now we
  are required to tell Python   
# for
  'Main' function existence  
if __name__=="__main__":
   
    Main()
   | 
வெளியீடூ:
Started
Enter integer: 5
Iteration
(Looping) 
இது குறிபிட்ட வரிகளை மீண்டும் மீண்டும் இயங்க வைக்க
பயன்படுகின்றது.
| 
# Python
  program to illustrate  
# a
  simple for loop  
for step in range(5):    
   
    print(step)
   | 
வெளியீடு:
0
1
2
3
4
பைத்தான்
ஆனது நிறைய லைப்ரரி மாடூல்களை கொண்டுள்ளது. அதை பயன்படுத்த import கீவேர்டு
இம்போர்ட் செய்து கொள்ள வேண்டும். உதாரணத்திற்கு கீழே உள்ள நிரலில் math என்கின்ற
மாடூல் பயன்படுத்தப்படுகின்றது. 
| 
# Python
  program to illustrate  
# math
  module  
import math  
def Main():  
    num
  =
  float(input("Enter
  a number: "))  
    #
  fabs is used to get the absolute value of a decimal  
    num
  =
  math.fabs(num) 
   
    print(num)
   
if __name__=="__main__":
   
    Main()
   | 
Output:
 Enter a number: 85.0
-முத்து
கார்த்திகேயன்,மதுரை.
 
 

 
 
No comments:
Post a Comment