Python for class 11 (CBSE Computer science sub code 083)Nitin Kumar
油
Right now I am in mid of completing this book. Just uploaded first and part of second chapter. Will upload whole once I am done.
Can contact me at nitin_k@outlook.com for more details or to get a copy of this book.
Python is a general purpose programming language that can be used for both programming and scripting. It was created in the 1990s by Guido van Rossum. Python is an interpreted language that is free, powerful, and portable. It can be used for tasks like web development, data analysis, and system scripting. The document provides an overview of Python including its history, uses, data types like strings and lists, and basic programming concepts like variables, conditionals, and loops. It recommends Python as a principal teaching language due to its free and easy installation, flexibility, use in academia and industry, and ability to offer a more rapid and enjoyable learning experience for students.
SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...Henry Schreiner
油
Building binary extensions is easier than ever thanks to several key libraries. Pybind11 provides a natural C++ language for extensions without requiring pre-processing or special dependencies. Scikit-build ties the premier C++ build system, CMake, into the Python extension build process. And cibuildwheel makes it easy to build highly compatible wheels for over 80 different platforms using CI or on your local machine. We will look at advancements to all three libraries over the last year, as well as future plans.
The document outlines the syllabus for a Python course, including introductions to data warehousing, Python itself, different modes in Python like file extensions and IDEs, data structures like sets and dictionaries, OS and exception handling modules, advanced topics like iterators and decorators, XML and multi-threading, web scraping, sequences and collections, lists and tuples, modules and packages, file handling, classes and objects, regular expressions, unit testing, web frameworks like Django, and GUI programming with Tkinter. The syllabus is designed to meet corporate requirements and covers many fundamental and advanced Python topics.
This presentation is a great resource for zero-based Python programmers who wants to learn Python 3. This course includes brief history of Python and familiarity of its basic syntax.
This document provides an overview of Git and GitHub. It describes Git as a version control system that allows developers to track changes to files, revert to previous versions, and collaborate on projects. Key Git commands are explained, such as initializing a repository, adding files, committing changes, and checking out different versions. The document also distinguishes between Git, which is installed locally, and GitHub, which hosts repositories in the cloud and allows sharing projects.
Python Programming - XIII. GUI ProgrammingRanel Padon
油
The document discusses Tkinter, the Python GUI programming interface. Tkinter provides a wrapper for the Tk GUI toolkit. Tk was originally created for Tcl but has bindings for other languages like Python through Tkinter. Tkinter allows Python programs to create graphical user interfaces by providing classes and methods that interface with the Tk GUI toolkit. Some key Tkinter widgets discussed include Frame, Label, Button, Entry, Radiobutton and Checkbutton. Pros of Tkinter include brevity, cross-platform support, maturity and extensibility. Potential cons are that it relies on Tcl/Tk which some consider unnecessary and it may have a theoretical speed disadvantage due to the multiple layers of interpretation.
This document provides an agenda and overview for a Python training course. The agenda covers key Python topics like dictionaries, conditional statements, loops, functions, modules, input/output, error handling, object-oriented programming and more. The introduction section explains that Python is an interpreted, interactive and object-oriented language well-suited for beginners. It also outlines features like rapid development, automatic memory management and support for procedural and object-oriented programming. The document concludes by explaining Python's core data types including numbers, strings, lists, tuples and dictionaries.
This document provides an introduction and overview of Python including sections on syntax, lists and dictionaries, for loops, and implementation examples. The introduction covers that Python code is indented using whitespace rather than brackets, semicolons are optional, and data types do not need declaration. Lists are described as arrays that can hold different data types indexed by number, while dictionaries hold key-value pairs indexed by keys that can be numbers, strings, or other data types. For loops in Python iterate over each item in a list or dictionary without needing an explicit condition. The implementation section provides examples of using for loops over lists, creating and accessing a dictionary of fruits, and making lists of dictionaries to demonstrate Python concepts.
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
油
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on Python Functions tutorial covers all the important aspects of functions in Python right from the introduction to what functions are, all the way till checking out the major functions and using the code-first approach to understand them better.
Agenda
Why use Functions?
What are the Functions?
Types of Python Functions
Built-in Functions in Python
User-defined Functions in Python
Python Lambda Function
Conclusion
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
This presentation provides the information on python including the topics Python features, applications, variables and operators in python, control statements, numbers, strings, print formatting, list and list comprehension, dictionaries, tuples, files, sets, boolean, mehtods and functions, lambda expressions and a sample project using Python.
In this talk, Jason will introduce tmux, the terminal multiplexer. Hell cover why youd want to use it, and then teach you how to actually use it with practical examples. Hell teach you his favorite key bindings, and then go into some incredibly handy plugins that you can use that will make your tmux experience so much better. Once you are done learning tmux, youll never understand how you got along without it.
Python is one of the powerful, high-level, easy to learn programming language that
provides a huge number of applications. Some of its features, such as being object-oriented
and open source, having numerous IDEs, etc. make it one of the most in-demand
programming languages of the present IT industry.
According to TIOBE index, as of January 2020, Python is one of the popular programming
languages. By looking at the popularity of this programming language, many IT
professionals, both beginners as well as experienced alike, are willing to build their career
as a Python developer
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Victor Rentea
油
Are you in a mood for a brainstorm? Join this critical review of the major decisions taken in a typical enterprise application architecture and learn to balance pragmatism with your design goals. Find out how to do just-in-time design to keep as much use-cases as simple as possible. The core purpose of this presentation is to learn to strike a **balance between pragmatism and maintainability** in your design. Without continuous refactoring, a simple design will inevitably degenerate into a Big Ball of Mud, under the assault of the new features and bugfixes. On the other hand, very highly-factored code can burden the take-off of the development and end up freezing the mindset in some rigid 'a-priori' design. The end goal of this talk is to challenge you to rethink critically the architecture of your own systems, and seek ways to simplify it to match your actual needs, with a pragmatic mindset. "Architecture is the art of postponing decisions", said Uncle Bob. This talk takes this idea further and explains an optimal mindset about designing enterprise applications: Evolving (Continuously Refactoring) a Pragmatic (Simple), Clean (aka Onion) Architecture, aiming to provide Developer Safety鏝 and Comfort鏝. Its the philosophy that Victor distilled over the past 5 years, designing and implementing 9 applications as IBM Lead Architect, and delivering trainings and advises to many other companies. Youll learn how to break data into pieces (Fit Entities, Value Objects, Data Transfer Objects), how to keep the logic simple (Facades, Domain Services, logic extraction patterns, Mappers, AOP), layering to enforce boundaries (keeping DTOs out of your logic, Dependency Inversion Principle), and many more, all in a dynamic, interactive and extremely entertaining session.
This document provides an overview of Linux history and features. It discusses that Unix was developed in 1969 at Bell Labs and led to various variants. Linux was developed in 1991 by Linus Torvalds as an open source clone of Unix. It discusses some popular Linux distributions like Red Hat, Ubuntu, Debian etc. It then covers basic Linux commands, text editors like Vi and Emacs, available software packages, user management and how to setup a basic web server. It encourages computer engineers to learn Linux as most professional applications and tools are available on Linux platforms.
this presentation will walk you through basic introduction to python, major features of python, how python runs on our system and some important commands used in python.
This document discusses semantic versioning for APIs and applications. It explains that the major, minor, and micro parts of a semantic version number indicate different levels of backward compatibility. A higher major version means the API is not backward compatible, a higher minor version means the API is backward compatible for consumers but not providers, and a higher micro version does not impact backward compatibility. It also mentions some tools for implementing semantic versioning.
This document provides an overview of version control systems, including their benefits and basic functions. Version control systems allow recording changes to files over time, allowing users to recall specific file versions. They offer advantages like backup and restoration of files, synchronization across multiple computers, and facilitating collaboration on teams. The document defines common version control terms and best practices for users.
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
油
If you're absolutely new to Python, and to programming in general, this is the place to start!
Here's the breakdown: by the end of this workshop, you'll have Python downloaded onto your personal machine; have a general idea of what Python can help you do; be pointed in the direction of some excellent practice materials; and have a basic understanding of the syntax of the language.
Please don't forget to bring your laptop!
Audience: "Python 101" is geared toward individuals who are new to programming. If you've had some programming experience (shell scripting, MATLAB, Ruby, etc.), then you'll probably want to check out the more intermediate workshop, "Python 101++".
This document is the preface to the book "Python for Informatics: Remixing an Open Book". It discusses how the book was created by modifying the open source book "Think Python" by Allen B. Downey to have a stronger focus on data analysis and exploring information using Python. Key changes included replacing number examples with data examples, reorganizing topics to get to data analysis quicker, and adding new chapters on data-related Python topics like regular expressions, web scraping, and databases. The goal was to produce a text suitable for a first technology course with an informatics rather than computer science focus.
Python is a multi-paradigm programming language created in 1989 by Guido van Rossum. It is based on ABC and Modula-3 and was named after Monty Python. Python has a simple syntax and dynamic typing and memory management. It can be used for web development, data science, scientific computing, and more. The core philosophy is summarized in the Zen of Python document. Python code is written, tested, and executed using integrated development environments like PyCharm or directly from the command line.
Introduction about Python by JanBask Training, we are offering Online Pyton Training. You should visit: http://www.janbasktraining.com/python/ for Pyton Training.
This document provides an overview of the basics of Linux, including its key components and common commands. It describes Linux as an open source, Unix-based operating system developed by the community. The core component is the Linux kernel, which uses a monolithic microkernel design. Common shells for the user interface include BASH, SH, and KSH. Basic commands covered include ls, cd, pwd, echo, cat, cp, mv, mkdir, rm, and tar for archiving and compressing files. The document also discusses file permissions and ownership, represented using octal notation, and crontab for scheduling tasks.
This document provides an overview of the differences between SystemV and systemd for initializing Linux systems. It begins with some background on systemd and its objectives to improve on outdated SystemV startup processes. The document then covers key aspects of systemd such as its functions, strategy of on-demand starting of services, and implementation details. It also discusses the benefits of systemd and compares some pros and cons between the two approaches.
This document provides an overview of Git and GitHub. It describes Git as a version control system that allows developers to track changes to files, revert to previous versions, and collaborate on projects. Key Git commands are explained, such as initializing a repository, adding files, committing changes, and checking out different versions. The document also distinguishes between Git, which is installed locally, and GitHub, which hosts repositories in the cloud and allows sharing projects.
Python Programming - XIII. GUI ProgrammingRanel Padon
油
The document discusses Tkinter, the Python GUI programming interface. Tkinter provides a wrapper for the Tk GUI toolkit. Tk was originally created for Tcl but has bindings for other languages like Python through Tkinter. Tkinter allows Python programs to create graphical user interfaces by providing classes and methods that interface with the Tk GUI toolkit. Some key Tkinter widgets discussed include Frame, Label, Button, Entry, Radiobutton and Checkbutton. Pros of Tkinter include brevity, cross-platform support, maturity and extensibility. Potential cons are that it relies on Tcl/Tk which some consider unnecessary and it may have a theoretical speed disadvantage due to the multiple layers of interpretation.
This document provides an agenda and overview for a Python training course. The agenda covers key Python topics like dictionaries, conditional statements, loops, functions, modules, input/output, error handling, object-oriented programming and more. The introduction section explains that Python is an interpreted, interactive and object-oriented language well-suited for beginners. It also outlines features like rapid development, automatic memory management and support for procedural and object-oriented programming. The document concludes by explaining Python's core data types including numbers, strings, lists, tuples and dictionaries.
This document provides an introduction and overview of Python including sections on syntax, lists and dictionaries, for loops, and implementation examples. The introduction covers that Python code is indented using whitespace rather than brackets, semicolons are optional, and data types do not need declaration. Lists are described as arrays that can hold different data types indexed by number, while dictionaries hold key-value pairs indexed by keys that can be numbers, strings, or other data types. For loops in Python iterate over each item in a list or dictionary without needing an explicit condition. The implementation section provides examples of using for loops over lists, creating and accessing a dictionary of fruits, and making lists of dictionaries to demonstrate Python concepts.
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
油
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on Python Functions tutorial covers all the important aspects of functions in Python right from the introduction to what functions are, all the way till checking out the major functions and using the code-first approach to understand them better.
Agenda
Why use Functions?
What are the Functions?
Types of Python Functions
Built-in Functions in Python
User-defined Functions in Python
Python Lambda Function
Conclusion
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
This presentation provides the information on python including the topics Python features, applications, variables and operators in python, control statements, numbers, strings, print formatting, list and list comprehension, dictionaries, tuples, files, sets, boolean, mehtods and functions, lambda expressions and a sample project using Python.
In this talk, Jason will introduce tmux, the terminal multiplexer. Hell cover why youd want to use it, and then teach you how to actually use it with practical examples. Hell teach you his favorite key bindings, and then go into some incredibly handy plugins that you can use that will make your tmux experience so much better. Once you are done learning tmux, youll never understand how you got along without it.
Python is one of the powerful, high-level, easy to learn programming language that
provides a huge number of applications. Some of its features, such as being object-oriented
and open source, having numerous IDEs, etc. make it one of the most in-demand
programming languages of the present IT industry.
According to TIOBE index, as of January 2020, Python is one of the popular programming
languages. By looking at the popularity of this programming language, many IT
professionals, both beginners as well as experienced alike, are willing to build their career
as a Python developer
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Victor Rentea
油
Are you in a mood for a brainstorm? Join this critical review of the major decisions taken in a typical enterprise application architecture and learn to balance pragmatism with your design goals. Find out how to do just-in-time design to keep as much use-cases as simple as possible. The core purpose of this presentation is to learn to strike a **balance between pragmatism and maintainability** in your design. Without continuous refactoring, a simple design will inevitably degenerate into a Big Ball of Mud, under the assault of the new features and bugfixes. On the other hand, very highly-factored code can burden the take-off of the development and end up freezing the mindset in some rigid 'a-priori' design. The end goal of this talk is to challenge you to rethink critically the architecture of your own systems, and seek ways to simplify it to match your actual needs, with a pragmatic mindset. "Architecture is the art of postponing decisions", said Uncle Bob. This talk takes this idea further and explains an optimal mindset about designing enterprise applications: Evolving (Continuously Refactoring) a Pragmatic (Simple), Clean (aka Onion) Architecture, aiming to provide Developer Safety鏝 and Comfort鏝. Its the philosophy that Victor distilled over the past 5 years, designing and implementing 9 applications as IBM Lead Architect, and delivering trainings and advises to many other companies. Youll learn how to break data into pieces (Fit Entities, Value Objects, Data Transfer Objects), how to keep the logic simple (Facades, Domain Services, logic extraction patterns, Mappers, AOP), layering to enforce boundaries (keeping DTOs out of your logic, Dependency Inversion Principle), and many more, all in a dynamic, interactive and extremely entertaining session.
This document provides an overview of Linux history and features. It discusses that Unix was developed in 1969 at Bell Labs and led to various variants. Linux was developed in 1991 by Linus Torvalds as an open source clone of Unix. It discusses some popular Linux distributions like Red Hat, Ubuntu, Debian etc. It then covers basic Linux commands, text editors like Vi and Emacs, available software packages, user management and how to setup a basic web server. It encourages computer engineers to learn Linux as most professional applications and tools are available on Linux platforms.
this presentation will walk you through basic introduction to python, major features of python, how python runs on our system and some important commands used in python.
This document discusses semantic versioning for APIs and applications. It explains that the major, minor, and micro parts of a semantic version number indicate different levels of backward compatibility. A higher major version means the API is not backward compatible, a higher minor version means the API is backward compatible for consumers but not providers, and a higher micro version does not impact backward compatibility. It also mentions some tools for implementing semantic versioning.
This document provides an overview of version control systems, including their benefits and basic functions. Version control systems allow recording changes to files over time, allowing users to recall specific file versions. They offer advantages like backup and restoration of files, synchronization across multiple computers, and facilitating collaboration on teams. The document defines common version control terms and best practices for users.
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
油
If you're absolutely new to Python, and to programming in general, this is the place to start!
Here's the breakdown: by the end of this workshop, you'll have Python downloaded onto your personal machine; have a general idea of what Python can help you do; be pointed in the direction of some excellent practice materials; and have a basic understanding of the syntax of the language.
Please don't forget to bring your laptop!
Audience: "Python 101" is geared toward individuals who are new to programming. If you've had some programming experience (shell scripting, MATLAB, Ruby, etc.), then you'll probably want to check out the more intermediate workshop, "Python 101++".
This document is the preface to the book "Python for Informatics: Remixing an Open Book". It discusses how the book was created by modifying the open source book "Think Python" by Allen B. Downey to have a stronger focus on data analysis and exploring information using Python. Key changes included replacing number examples with data examples, reorganizing topics to get to data analysis quicker, and adding new chapters on data-related Python topics like regular expressions, web scraping, and databases. The goal was to produce a text suitable for a first technology course with an informatics rather than computer science focus.
Python is a multi-paradigm programming language created in 1989 by Guido van Rossum. It is based on ABC and Modula-3 and was named after Monty Python. Python has a simple syntax and dynamic typing and memory management. It can be used for web development, data science, scientific computing, and more. The core philosophy is summarized in the Zen of Python document. Python code is written, tested, and executed using integrated development environments like PyCharm or directly from the command line.
Introduction about Python by JanBask Training, we are offering Online Pyton Training. You should visit: http://www.janbasktraining.com/python/ for Pyton Training.
This document provides an overview of the basics of Linux, including its key components and common commands. It describes Linux as an open source, Unix-based operating system developed by the community. The core component is the Linux kernel, which uses a monolithic microkernel design. Common shells for the user interface include BASH, SH, and KSH. Basic commands covered include ls, cd, pwd, echo, cat, cp, mv, mkdir, rm, and tar for archiving and compressing files. The document also discusses file permissions and ownership, represented using octal notation, and crontab for scheduling tasks.
This document provides an overview of the differences between SystemV and systemd for initializing Linux systems. It begins with some background on systemd and its objectives to improve on outdated SystemV startup processes. The document then covers key aspects of systemd such as its functions, strategy of on-demand starting of services, and implementation details. It also discusses the benefits of systemd and compares some pros and cons between the two approaches.
Linux'a Giris ve VirtualBox a Ubuntu KurulumuAhmet G端rel
油
Bu d旦k端man Linux nedir neden tercih edilir gibi sorulara cevap arayanlara k脹sa bir bilgilendirmeden sonra Sanal makinaya Linux Ubuntu da脹t脹m脹n脹n kurulumunu g旦stererek genel linux terminal ve komutlar脹n脹n anlat脹m脹yla son bulmaktad脹r.L聴nux ve 旦zg端r yaz脹l脹m fark脹ndal脹脹n脹 art脹rmak i巽in giri seviyesinde bir d旦kumand脹r.聴inize yaramas脹 dileiyle iyi 巽al脹malar.Soru,g旦r端 ve 旦nerileriniz i巽in ahmet@gurelahmet.com a mail atabilirsiniz.
Gereksinim analizi 巽al脹malar脹 yaz脹l脹m projelerinin baar脹ya ulaabilmesi i巽in yap脹lmas脹 gereken en 旦nemli itir. Doru ekilde ihtiya巽lar脹 ortaya konmu projeler ancak baar脹l脹 olabilirler.Gereksinim analiz 巽al脹malar脹 iki aamadan meydana gelir; Gereksinimlerin ortaya 巽脹kar脹lmas脹
Gereksinimlerin 旦ncelik durumuna g旦re analiz edilmesi. Bu sunumda iyi bir proje i巽in gerekli olan gereksinim analiz dok端man脹 haz脹rlama y旦ntemi verilmitir.
The document discusses the ALGOL family of programming languages, including their history and goals. It describes the three versions of ALGOL: ALGOL 58, which introduced features like types and control structures; ALGOL 60, which refined the syntax and added block structures and recursion; and ALGOL 68, which had a more advanced type system but was difficult to adopt. While ALGOL did not achieve wide commercial success, it was influential in establishing concepts like block structures, recursion, and formal syntax specification that became standard in later languages.
2. G聴R聴
Python ilk olarak 1990lar脹n ba脹nda Guido van Rossum
taraf脹ndan ABC adl脹 bir dilin devam脹 olarak gelitirilmeye
balanm脹t脹r. 聴lk olarak CWI b端nyesinde gelitirilen
Python daha sonra s脹ras脹yla CNRI ve BeOpen Labs.
b端nyesinde gelitirilmitir. G端n端m端zde ise
gelitirilmesine Python Software Foundation taraf脹ndan
devam edilmektedir. 1.6.1 s端r端m端nden beri GPL uyumlu
bir lisans olan Python Lisans脹 alt脹nda da脹t脹lmaktad脹r
3. NEDEN PYTHON?
Pyhton'un Genel zellikleri:
1- Nesneye Y旦nelik Bir Dildir
Python'da herey bir nesnedir Fonksiyonlar, Deikenler, Sabitler,
S脹n脹flar ve Mod端ller birer nesnedir. En basit bir karakter sabiti bile
nesnedir
2- zg端rd端r
Python kaynak kodu a巽脹k, 旦zg端r bir dildir Kayna脹 C ile yaz脹lm脹t脹r Eer
C biliyorsan脹z kendinize has bir python yorumlay脹c脹s脹 yazabilir ve bu
yeni yorumlay脹c脹y脹 da脹tabilirsiniz
4. 3- Yorumlamal脹 / Derlemeli
Python'da yazd脹脹n脹z kodlar yorumlay脹c脹 taraf脹ndan 旦nce ara koda
(byte-code) 巽evrilir Daha sonra yine yorumlay脹c脹 taraf脹ndan
yorumlanarak 巽al脹t脹r脹l脹r Ara Koda 巽evirme ii olduk巽a h脹zl脹d脹r Ve eer
kodda bir deiiklik yap脹lmad脹ysa tekrar ara koda 巽evirmek yerine
dorudan daha 旦nceki ara koddan yorumlan脹r B旦ylece ara koda
巽evirme ilemi atlanarak 巽al脹t脹rma ilemine h脹zla ge巽ilir Hatta
program脹n脹z脹 bir baka yerde 巽al脹t脹rmak i巽in kaynak kod yerine direkt
olarak ara kodu g旦t端rebilirsiniz Ancak unu da belirtmek gerekir Ara
kodu 巽al脹t脹rmak i巽in yine de python yorumlay脹c脹s脹n脹n kurulu olmas脹
gerekir
Net platformuna 旦zg端 Python derleyicileri mevcut Bu derleyiciler
sayesinde Python yorumlay脹c脹s脹 olmadan derlenen programlar net
ortam脹nda 巽al脹t脹r脹labilmektedir Bu da ta脹nabilirlik olarak 旦nemlidir
5. 4- Ta脹nabilirlik
Pythonda yaz脹lm脹 bir program脹 Windows, Unix ve T端revleri, MacOs gibi pek
巽ok iletim sisteminde 巽al脹t脹rabilirsiniz Python programlar脹n脹n iletim sistemi
ve donan脹m ba脹ml脹l脹脹 olmad脹脹ndan ta脹nabilirlii olduk巽a y端ksektir Ancak
yine de belli bir iletim sistemine 旦zel mod端l kulland脹脹n脹zda bu ta脹nabilirlik
旦zelliini ortadan kald脹rabilir Eer belli bir platforma 旦zel bir program
yazm脹yorsan脹z o platforma 旦zg端 mod端lleri kullanmamal脹s脹n脹z
6. 5- G端巽l端d端r
Pythonda arad脹脹n脹z hemen hemen her eyi bulabilir, her t端rl端
uygulamay脹 gelitirebilirsiniz Unix taban脹nda C/C++
k端t端phanelerini kullanabilir, g端巽l端 COM destei sayesinde
windowsta Visual C++'脹n g端c端n端 kullanabilirsiniz COM destei ile
windows uygulamalar脹na eriip her istediinizi yapt脹rabilirsiniz
6- H脹zl脹d脹r
Python bir alt benzeri olan Java'ya oranla olduk巽a h脹zl脹d脹r
Pythonda mod端ller ba脹ms脹z olduklar脹ndan istemediiniz Hi巽bir
mod端l haf脹zaya y端klenmez B旦ylelikle hem bellek kullan脹m脹 d端er,
hemde uygulaman脹za daha hakim olursunuz Ayr脹ca tan脹ml脹
nesnelerle iiniz bittiinde haf脹zadan silinecek ve haf脹za gereksiz
yere megul edilmeyecektir
7. 7- Yaz脹m脹 Kolayd脹r
Kullan脹m脹 ve yaz脹m脹 olduk巽a kolay bir dildir Kod yaz脹m kurallar脹 巽ok
s脹k脹 olduundan sizi d端zenli kod yazmaya itecektir Bu da bug端n
yazd脹脹n脹z bir kodu 5 y脹l sonra bile rahat巽a anlayabilmenize olanak
tan脹r Ayr脹ca pek 巽ok dile g旦re ayn脹 ii daha az kod yazarak
yapabilirsiniz
8. 8- Kullan脹m Alan脹
Pythonu Veritaban脹 programc脹l脹脹 ve Internet programc脹l脹脹nda
kullanabilirsiniz Yani Pythonla hem ticari uygulamalar gelitirebilir hem de
dinamik internet sayfalar脹 haz脹rlayabilirsiniz
Python programlama dili son d旦nemlerde olduk巽a pop端lerlik kazand脹
rnein Pardus Linux iletim sisteminin 巽ok b端y端k bir destei mevcut Pek
巽ok uygulama Pythonda yaz脹lm脹 durumda Yine ayn脹 ekilde RedHat'脹n
kurulum arabirimi ve dier pek 巽ok program pythonla yaz脹lm脹 durumda
Google, Nasa, Yahoo gibi pek 巽ok firma python kullan脹yor
Yanl脹 anlama
Python kelimesi asl脹nda 巽ou kiinin zannettii gibi "Piton Y脹lan脹" anlam脹na
gelmiyor. "Python ismi Guido Van Rossum'un 巽ok sevdii, "Monty
Python" adl脹 alt脹 kiilik bir 聴ngiliz komedi grubunun "Monty Python's Flying
Circus" adl脹 g旦sterisinden geliyor. Guido Van Rossum Python'u
gelitirmeye 1990 y脹l脹nda balam脹... Yani asl脹nda Python i巽in nispeten yeni
bir dil deneb
9. GENEL ZELL聴KLER
Python her ne kadar bir script dili olsa da dier scripting dillerinde olan baz脹
旦zellikleri i巽ermez.
Pythonda k端巽端k-b端y端k harf ayr脹m脹 mevcuttur. Bu nedenle foobar, fooBar ve
FooBar birbirinden farkl脹 nesnelerdir.
Pythonda deikenler kullan脹lmadan 旦nce mutlaka ilklendirilmelidir
(initialization). Python yorumlay脹c脹s脹 deikenlere kullan脹ld脹脹 yere g旦re otomatik
bir deer atamayacakt脹r.
仰lklendirilmemi bir deeri kullanmaya kalkt脹脹n脹zda bir NameError ile
kar脹la脹rs脹n脹z. Ancak buna ramen deikenlerin tiplerinin herhangi bir 旦zel yerde
tan脹mlanmas脹 gerekmez, 旦rnein kirkiki=42 yazd脹脹m脹zda kirkiki adl脹 deiken
otomatik olarak integer veri tipine sahip olacakt脹r.
Son olarak Pythonda herey bir nesnedir. Bu nedenle mesela bir deikene
atamadan dorudan kullanaca脹m脹z bir string de bir string deikenle ayn脹
旦zelliklere sahiptir.
10. KOD YAZMAK 聴聴N
Python kodlar脹n脹 yazmak i巽in iki se巽eneimiz var. Birincisi kodlar脹m脹z脹
dorudan Python
komut sat脹r脹na yazabiliyoruz. Python komut sat脹r脹n脹 a巽mak i巽in ALT+F2
tular脹na bas脹p
巽脹kan ekrana "konsole" yazmam脹z, ard脹ndan da konsolda "python"
komutunu vermemiz
gerekiyor. Bu ekranda komutlar脹m脹z脹 ">>>" iaretinden hemen sonra
yazaca脹z.
聴kinci se巽eneimiz ise bir metin d端zenleyici kullanmakt脹r. Baz脹 ufak
kodlar脹 denemek i巽in
komut sat脹r脹 yeterli olsa da hem kodlar脹m脹z脹 kaydetmek hem de b端y端k
programlarda rahat
hareket edebilmek i巽in mutlaka bir metin d端zenleyici kullanmam脹z
gerekiyor. u aamada
kullan脹m kolayl脹脹 nedeniyle "kwrite" metin d端zenleyici 旦nerilebilir.
ALT+F2 tular脹na bas脹p "kwrite" yazarak bo bir kwrite belgesi
a巽abiliriz.
Python kodlar脹n脹 yazmaya balamadan 旦nce, bo belgenin ilk sat脹r脹na
#!/usr/bin/env python
yazmam脹z gerekiyor. Bu sat脹r sayesinde sistemimiz, yazd脹脹m脹z kodlar脹n
hangi program taraf脹ndan 巽al脹t脹r脹laca脹n脹 anl脹yor.
11. 聴te Pythonca Hello World!:
print "Hello world!
Yorum Sat脹rlar脹
Pythonda iki tip yorum sat脹r脹 mevcuttur. Tek sat脹rl脹k yorumlar #
karakteri ile balarlar. Birden fazla sat脹ra sahip yorumlar ise
karakterleri ile balay脹p ayn脹 ekildekapan脹rlar.
12. KULLANICIYLA 聴LET聴聴M: VER聴 ALI-
VER聴聴
Python'da kullan脹c脹dan birtak脹m veriler alabilmek, yani
kullan脹c脹yla iletiime ge巽ebilmek i巽in ikitane fonksiyondan
faydalan脹l脹r. Bunlardan 旦ncelikle ilkine bakal脹m:
1.raw_input() fonksiyonu
#!/usr/bin/env python
# -*- coding: utf-8 -*-
a=raw_input("L端tfen parolan脹z脹 girin:")
print "Teekk端rler!
imdi bu belgeyi "deneme.py" ismiyle kaydediyoruz. Daha
sonra bir konsol ekran脹 a巽脹p,
program脹m脹z脹n kay脹tl脹 olduu dizine ge巽erek u komutla
program脹m脹z脹 巽al脹t脹r脹yoruz:
python deneme.py
13. imdi raw_input fonksiyonuna bir ara verip, kullan脹c脹dan bilgi almak i巽in
kullanabileceimiz ikinci fonksiyondan biraz bahsedelim.
2.input() fonksiyonu
T脹pk脹 raw_input fonksiyonunda olduu gibi, bu komutla da kullan脹c脹lardan
baz脹 bilgileri
alabiliyoruz. u basit 旦rnee bir bakal脹m:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
a = input("L端tfen bir say脹 girin:")
b = input("L端tfen baka bir say脹 daha girin:")
print a + b
raw_input() fonksiyonunun, girilen verileri "karakter dizisi" (string) olarak;
input() fonksiyonunun ise "tamsay脹" (integer) olarak alg脹lan脹r.
14. PYTHON'DA KOULA BALI DURUMLAR
Bu i i巽in kullanaca脹m脹z 端巽 tane ifade var: if..., else: ve elif...
#!/usr/bin/env python
#-*- coding: utf-8 -*-
meyve = raw_input("Bir meyve ad脹 yaz脹n脹z: ")
if meyve = = "elma":
print "elma bir meyvedir"
elif meyve = = "armut":
print "armut bir meyvedir"
else:
print meyve, "bir meyve deildir!"
15. PYTHON'DA
DNGLER
1.while d旦ng端s端
#!/usr/bin/env python
#-*- coding: utf-8 -*-
a=0
while a < 100:
a=a+1
print a
#!/usr/bin/env python
#-*- coding: utf-8 -*-
soru = raw_input("Arkada脹m sen deli misin?")
while soru != "hay脹r":
print "delisin sen deli! Kulaklar脹 k端peli!
Dikkat ederseniz burada da ile巽lerimizden birini kulland脹k. Kulland脹脹m脹z
ile巽 "eit deildir anlam脹na gelen "!=" ileci...
16. 2.For d旦ng端s端
#!/usr/bin/env python
#-*- coding: utf-8 -*-
for zombi in range(1, 100):
print zombi
Ben burada deiken ad脹 olarak zombi kelimesini kulland脹m,siz isterseniz
Osman da kullanabilirsiniz
#!/usr/bin/env python
#-*- coding: utf-8 -*-
for kelimeler in "linux":
print kelimeler
G旦rd端端n端z gibi, for d旦ng端s端yle yaln脹zca say脹lar脹 deil, karakter dizilerinin
旦elerini de d旦kebiliyoruz ekrana.
17. 3.range() fonksiyonu
Bu fonksiyon Python'da say脹 aral脹klar脹n脹 belirtmemizi salar. print
range(100)
komutu 0 ile 100 aras脹ndaki say脹lar脹 yazd脹rmam脹z脹 salar.
Baka bir 旦rnek daha verelim:
print range(100,200)
komutu 100 ile 200 aras脹ndaki say脹lar脹 d旦ker.
Bir 旦rnek daha:
print range(1,100,2)
Bu komut ise 1 ile 100 aras脹ndaki say脹lar脹 2'er 2'er atlayarak
yazd脹rmam脹z脹 salar...
18. 4.len() fonksiyonu
Bu fonksiyon, karakter dizilerinin uzunluunu g旦sterir.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
a = "Afyonkarahisar"
print len(a)
Bu kod, "Afyonkarahisar" karakter dizisi i巽indeki harflerin
say脹s脹n脹 ekrana d旦kecektir.
19. 5.Break ifadesi
break ifadesi program i巽inde bir noktada program脹 sona erdirmek
gerektii zaman kullan脹l脹r.
Aa脹daki 旦rnek break ifadesinin ne ie yarad脹脹n脹 a巽脹k巽a g旦steriyor:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
kullanici_adi = "kullanici"
parola = "sifre"
while True:
soru1 = raw_input("Kullan脹c脹 ad脹: ")
soru2 = raw_input("ifre: ")
if soru1 = = kullanici_adi and soru2 = = parola:
print "Kullan脹c脹 ad脹 ve ifreniz onayland脹. Programa hogeldiniz!
break
else:
print "Kullan脹c脹 ad脹n脹z veya ifrenizden en az birisi onaylanmad脹.
20. 6.continue ifadesi
Bu ifade ise d旦ng端 i巽inde bir bloun es ge巽ilip ondan sonraki bloun
巽al脹t脹r脹lmas脹n脹 salar. ok bilindik bir 旦rnek verelim:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
while True:
s = raw_input("Bir say脹 girin: ")
if s = = "iptal":
break
if len(s) <= 3:
continue
print "En fazla 端巽 haneli bir say脹 girebilirsiniz."
21. PYTHON'DA L聴STELER, DEMETLER, SZLKLER
Listeler
Python'da herhangi bir liste oluturmak i巽in 旦nce listemize bir ad vermemiz,
ard脹ndan da k旦eli parantez kullanarak bu listenin 旦elerini belirlememiz
gerekiyor.
liste = ["Hale", "Jale", "Lale", 12, 23]
Python komut sat脹r脹nda u ifadeyi yaz脹n:
type("Hale")
Bu komutun 巽脹kt脹s脹:
<type 'str'>
imdi ayn脹 komutu u ekilde deniyoruz:
type(123)
Bu komut bize u 巽脹kt脹y脹 verecektir:
<type 'int'>
imdi komut sat脹r脹nda
liste
yazd脹脹m脹zda tan脹mlad脹脹m脹z "liste" adl脹 listenin 旦eleri ekrana yazd脹r脹lacakt脹r.
Tan脹mlad脹脹m脹z bu listenin 旦e say脹s脹n脹 len() fonksiyonu yard脹m脹yla 旦renebiliriz:
len(liste)
5
22. append par巽ac脹脹
聴lk par巽ac脹脹m脹z "append". Bu kelime T端rk巽e'de "eklemek, ilitirmek
anlam脹na geliyor...Oluturduumuz listeye yeni bir 旦e eklemek i巽in
"append" par巽ac脹脹ndan faydalan脹yoruz:
liste.append("Mehmet")
"Python, liste i巽indeki 旦eleri s脹ralarken, listenin ilk 旦esini 0'dan balat脹r."
insert par巽ac脹脹
聴te bu "insert" par巽ac脹脹 yard脹m脹yla listenin herhangi bir noktas脹na 旦e
ekleyebiliyoruz. Bu kelime T端rk巽e'de "yerletirmek, sokmak" anlam脹na
geliyor... insert par巽ac脹脹 yard脹m脹yla listenin 1. s脹ras脹na (Dikkat edin, 0'脹nc脹
s脹raya demiyoruz) "Ahmet"i yerletirebiliriz:
liste.insert(1, "Ahmet")
Burada parantez i巽indeki ilk say脹, "Ahmet" 旦esinin liste i巽inde yerletirile-
cei s脹ray脹 g旦sterir. Bu komutun 巽脹kt脹s脹 旦yle olur:
["Hale", "Ahmet", "Jale", "Lale", 12, 23, "Mehmet"]
23. extend par巽ac脹脹
yeni_liste = ["Simovic", "Prekazi", "Jardel", "Nouma"]
liste.extend(yeni_liste)
Bu komutun 巽脹kt脹s脹 旦yle olacakt脹r:
['Veli', 'Hale', 'Ahmet', 'Jale', 'Lale', 12, 23, 'Mehmet', 'Simovic', 'Prekazi', 'Jardel',
'Nouma']
remove par巽ac脹脹
liste.remove("Nouma")
listeden nouma silinir.
pop par巽ac脹脹
liste.pop()
G旦rd端端n端z gibi, Python bu pop par巽ac脹脹 yard脹m脹yla listenin son
旦esini 巽脹karacak, 端stelik 巽脹kard脹脹 旦eyi ekrana yazd脹racakt脹r. Eer
bu komutu 旦yle verirsek ne olur?
liste.pop(0)
Bu komut ise listedeki "ilk" yani "0'脹nc脹" 旦eyi 巽脹kar脹r ve 巽脹kard脹脹
旦eyi ekrana yazd脹r脹r.
reverse par巽ac脹脹
Bu par巽ac脹k listedeki 旦elerin s脹ras脹n脹 ters y端z eder. 旦yle ki:
liste.reverse()
Bu komutu 端st 端ste iki kez verirseniz listeniz ilk haline d旦necektir.
24. count par巽ac脹脹
Listelerle birlikte kullanabileceimiz baka bir par巽ac脹k da
budur. G旦revi ise liste i巽inde bir 旦enin ka巽 kez ge巽tiini
s旦ylemektir:
liste.count("Prekazi")
index par巽ac脹脹
Diyelim ki listedeki "Jardel" 旦esinin listenin ka巽脹nc脹 s脹ras脹nda olduunu
merak ediyorsunuz. 聴te bu index par巽ac脹脹 sizin arad脹脹n脹z ey! Bu
par巽ac脹脹 旦yle kullan脹yoruz:
liste.index("Jardel")
sort par巽ac脹脹
Bazen listemizdeki 旦eleri alfabe s脹ras脹na dizmek isteriz. 聴te y端reimizde
b旦yle bir istek has脹l olduunda kullanaca脹m脹z par巽ac脹脹n ad脹 "sort":
liste.sort()
25. Demetler
Demetler (tuples) listelere benzer. Ama listeler ile aralar脹nda 巽ok temel bir fark
vard脹r. Listeler 端zerinde oynamalar yapabiliriz. Yani 旦e ekleyebilir, 旦e 巽脹karabiliriz.
Demetlerde ise b旦yle bir ey yoktur...
Demeti u ekilde tan脹ml脹yoruz:
demet = "Ali", "Veli", 49, 50
G旦rd端端n端z gibi, yapt脹脹m脹z bu i deiken tan脹mlamaya 巽ok benziyor. 聴stersek
demetin
elerini parantez i巽inde de g旦sterebiliriz.
demet2 = ("Ali", "Veli", 49, 50)
Peki bo bir demet nas脹l oluturulur? ok basit:
demet = ()
Peki tek 旦eli bir demet nas脹l oluturulur? O kadar basit deil. Asl脹nda basit ama biraz
tuhaf:
hede = ("inek",)
Yukar脹da anlatt脹脹m脹z ekilde bir demet oluturma iine "demetleme" (tuple packing)
ad脹 veriliyor. Bunun tersini de yapabiliriz. Buna da "demet a巽ma" deniyor (sequence
unpacking):
nce demetleyelim:
aile = "Anne", "Baba", "Kardesler"
imdi demeti a巽al脹m:
a, b, c = aile
Bu ekilde komut sat脹r脹na "a" yazarsak, "Anne" 旦esi; "b" yazarsak "Baba" 旦esi; c
Yazarsak "Kardesler" 旦esi ekrana yazd脹r脹lacakt脹r.
26. S旦zl端kler
sozluk = {"elma": "meyve", "domates": "sebze", 1: "sayi"}
telefon_defteri = {"Ahmet": "0533 123 45 67",
"Kezban": "0532 321 54 76", "Feristah": "0533 333 33 33"}
Burada 旦rnein, "elma" bir "anahtar", "meyve" ise bu anahtar脹n
"deeri"dir. Ayn脹 ekilde "sebze deerinin anahtar脹 "domates"tir.
Dolay脹s脹yla Python'da s旦zl端k; "anahtar" ve "deer" aras脹ndaki ilikiyi
g旦steren bir veri tipidir!
imdi gelelim bu s旦zl端kleri nas脹l y旦neteceimize... Diyelim ki
s旦zl端端m端ze yeni bir 旦e eklemek istiyoruz:
telefon_defteri["Zekiye"] = "0544 444 01 00
Eer biz s旦zl端kteki b端t端n 旦eleri silmek istersek u komut kullan脹l脹yor:
telefon_defteri.clear()
27. FONKS聴YON TANIMLAMA
Fonksiyonlar脹 tan脹mlarken "def" adl脹 bir par巽ac脹ktan yararlanaca脹z. Bu
"def" par巽ac脹脹n脹n hemen ard脹ndan ise fonksiyonumuzun ad脹n脹
belirleme- miz gerekiyor...
def ilk_fonksiyonumuz():
print "Ben Python! Monty Python!
Fonksiyonlarda Parametreler
Args=demet ve kwargs=s旦zl端k
def foobar(foo, bar="42", *args, **kwargs):
...
Dikkat etmemiz gereken kural parametrelerin s脹ra脹n脹n 旦nce normal
parametreler, ard脹ndan 旦ntan脹ml脹 deere sahip parametreler,
ard脹ndan geri kalan parametreleri toplamak 端zere *args ve **kwargs
tan脹mlar脹n脹 kullanmakt脹r.
Pythonun fonksiyon tan脹mlar脹nda i巽erdii en 旦nemli kolayl脹k deiken
uzunluktaki parametre listeleridir. Bu sayede bir fonksiyonun s脹n脹rs脹z
say脹da parametre almas脹 salanabildii gibi bir demet, liste veya s旦zl端k
i巽erisindeki veriler de kolayca bir fonksiyona parametre olarak
ge巽irilebilir.( args adl脹 bir demet kwargs adl脹 bir s旦zl端kten 旦nce gelir)
28. Baka bir 旦rnek:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
def merhaba(arkadas):
print "Merhaba", arkadas
arkadas = "Kezban"
arkadas = "M端cella"
merhaba(arkadas)
Sizce Python burada kimi arkadatan sayacak? Kezban'脹 m脹 yoksa
M端cella'y脹 m脹?
Cevap: M端cella!
Peki bunun nedeni nedir?
Cevap: Python fonksiyonlarda deikenleri okumaya sondan balar...
Yukar脹daki 旦rnekte arkadas =
"M端cella" ifadesinin alt脹na arkadas = "Ahmet" ifadesini eklerseniz,
Python bu kez "Ahmet"i dikkate
alacakt脹r... 端nk端 bu kez en sonda "Ahmet" deeri olmu olacak...
29. "return" ifadesi
Bu ifadenin ne ie yarad脹脹n脹 anlamak i巽in u 旦rneklere bakal脹m:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
def return_deneme(a,b):
if a < b:
return a
else:
return b
print return_deneme(34, 45)
G旦rd端端n端z gibi burada "return" ifadesi yaratt脹脹m脹z koulun sonucuna g旦re
ya a deikenini ya da b deikenini "d旦nd端r端yor"; yani bize 巽脹kt脹 olarak
veriyor...
30. "pass" ifadesi
#!/usr/bin/python
def deneme():
liste = []
while True:
a = raw_input("Giriniz: ")
if a = = "0":
pass
else:
liste.append(a)
print liste
deneme()
Burada g旦rd端端m端z gibi, eer kullan脹c脹 "0" deerini girerse, bu deer
listeye eklenmeyecek,Python hi巽bir ey yapmadan bu sat脹r脹
atlayacakt脹r.
31. Veri Tipleri
1.Boolean deerler
Pythonun geni veri tipi se巽enekleri aras脹nda en yeni olan脹 boolean
deerlerdir. Python 2.2ye kadar True ve False anahtar kelimeleri
yoktur. 2.2de ise 0 ve 1 say脹lar脹na denk olarak bu kelimeler
getirildikten sonra sonunda 2.3 s端r端m端 ile Python ger巽ek bir boolean
tipine kavumutur. Boolean veri tipinin Pythonda bu
kadar ge巽 ortaya 存c脹kmas脹n脹n sebebi Pythonun Cye benzer bir
ekilde her t端rl端 veri tipini doruluk testinde kullanabiliyor olmas脹d脹r.
rnein bo bir string, bo bir liste veya 0 say脹s脹 yanl脹, 0 d脹脹ndaki
herhangi bir say脹, boyutu 0dan b端y端k olan herhangi bir liste veya
string ise doru kabul edilecektir. Bunun d脹脹nda
__nonzero__ adl脹 fonksiyonu kendi s脹n脹f脹m脹z脹n i巽erisinde
tan脹mlayarak kendi yarataca脹m脹z bir s脹n脹f脹 da doruluk testinde
kullanmak m端mk端nd端r.
32. 2.Say脹sal Tipler
Pythonda d旦rt temel say脹sal veri tipi bulunmaktad脹r.
1.integer (Tamsay脹),
2.long (Uzun tamsay脹),
3. float (Kayar noktal脹 say脹),
4. complex (Karma脹k say脹)
Bu veri tiplerinin tamam脹 iaretli say脹lard脹r. Gerektii
durumlarda Python yorumlay脹c脹s脹 integer, long ve float tipleri
aras脹nda otomatik deiimler yapabilmektedir. rnein Python
yorumlay脹c脹s脹na integer脹n s脹n脹rlar脹n脹 aan bir say脹 verdiiniz takdirde
yorumlay脹c脹 bunu otomatik olarak long tipine 巽evirecektir. Ayn脹
ekilde bir ilemin operandlar脹ndan birinin float olmas脹 halinde
sonu巽 da floata d旦necektir.
33. 3.String Tipleri
Python C printf tarz脹 metin bi存cimlendirme (String
Formatting) karakterlerini destekler. Bu bi巽imlendirme
karakterlerinin tam bir listesine
http://www.python.org/doc/current/lib/typesseq-strings
html adresinden ulaabilirsiniz.
Bu tip metin bi巽imlendirme ilemlerinde Pythonun
getirdii bir kolayl脹k bi巽imlenecek metnin i巽ine koyulacak
deerleri bir liste yerine s旦zl端kten alabilme 旦zelliidir. Bu
sayede bi巽imlendirilecek metnin i巽ine yerletirilecek
veriler
listedeki s脹ralar脹ndan ba脹ms脹z olarak isimleriyle
kullan脹labi-
lirler.
34. SINIF TANIMLAMAK
class IlkSinif:
mesele = "Olmak ya da olmamak"
rnekleme (Instantiation)
imdi 旦yle bir ey yaz脹yoruz:
>>>deneme = IlkSinif()
Art脹k u komut yard脹m脹yla, s脹n脹f 旦rneimizin niteliklerine ulaabiliriz:
>>>deneme.mesele
B旦ylece oluturduumuz s脹n脹f脹 bir deikene atad脹k. NTP kavramlar脹yla
konuacak olursak, s脹n脹f脹m脹z脹 旦rneklemi olduk.
旦p Toplama (Garbage Collection)
Peki biz bir s脹n脹f脹 旦rneklemezsek ne olur? Eer bir s脹n脹f脹 旦rneklemezsek, o
旦rneklenmeyen s脹n脹f program taraf脹ndan otomatik olarak "巽旦p toplama
(garbage collection) ad脹 verilen bir s端rece tabi tutulacakt脹r. Burada bu
s端recin ayr脹nt脹lar脹na girmeyeceiz. Ama k脹saca 旦yle anlatabiliriz: Python'da
(ve bir 巽ok programlama dilinde) yazd脹脹m脹z programlar i巽indeki "ie
yaramayan" veriler bellekten silinir. B旦ylece etkili bir haf脹za y旦netimi
uygulanm脹 ve programlar脹n performans脹 art脹r脹lm脹 olur.
35. __init__ Nedir?
#!/usr/bin/env python
#-*- coding:utf8 -*-
class Oyun:
def __init__(self):
enerji = 50
para = 100
fabrika = 4
isci = 10
print "enerji:", enerji
print "para:", para
print "fabrika:", fabrika
print "i巽i:", isci
macera = Oyun()
Pythonda bir program脹n ilk kez 巽al脹t脹r脹ld脹脹 anda ilemesini istediimiz eyleri bu __init__
fonksiyonu i巽ine yaz脹yoruz. Mesela yukar脹daki ufak oyun 巽al脹mas脹nda, oyuna baland脹脹 anda
Bir oyuncunun sahip olaca脹 旦zellikleri __init__ fonksiyonu i巽inde tan脹mlad脹k. Buna g旦re bu
Oyunda bir oyuncu oyuna balad脹脹nda;
enerjisi 50,
paras脹 100
fabrika say脹s脹 4,
i巽i say脹s脹 ise 10 olacakt脹r.
37. G旦rd端端n端z gibi, kodlar i巽inde yazd脹脹m脹z deikenlerin, fonksiyon d脹脹ndan da
巽ar脹labilmesi i巽in, yani bir bak脹ma "global" bir nitelik kazanmas脹 i巽in self olarak
tan脹mlanmalar脹 gerekiyor. Yani mesela, enerji yerine self.enerji diyerek, bu
enerji adl脹 deikenin yaln脹zca i巽inde bulunduu fonksiyonda deil, o
fonksiyonun d脹脹nda da kullan脹labilmesini sal脹yoruz. 聴yice somutlat脹rmak
gerekirse, __init__ fonksiyonu i巽inde tan脹mlad脹脹m脹z enerji adl脹 deiken, bu
haliyle goster adl脹 fonksiyonun i巽inde kullan脹lamaz. Daha da 旦nemlisi bu kodlar脹
bu haliyle tam olarak 巽al脹t脹ramay脹z da.
Mesela u temel komutlar脹 iletemeyiz:
macera.enerji
macera.para
macera.isci
macera.fabrika
38. M聴RAS ALMA
(INHER聴TANCE)
class Dusman(Oyun):
B旦ylelikle daha en bata tan脹mlad脹脹m脹z Oyun adl脹 s脹n脹f脹, bu
yeni oluturduumuz s脹n脹fa miras verdik. Dusman s脹n脹f脹n脹n
durumunu Pythoncada 旦yle ifade Dusman s脹n脹f脹 Oyun
s脹n脹f脹n脹 miras ald脹 (Dusman inherits from Oyun)
class Dusman(Oyun):
def __init__(self):
Oyun.__init__(self)
self.ego = 0
def goster(self):
Oyun.goster(self)
print "ego:", self.ego
39. Eski ve Yeni S脹n脹flar
imdiye kadar verdiimiz s脹n脹f 旦rneklerinde 旦nemli bir konudan
hi巽 bahsetmedik. Python'da iki tip
s脹n脹f vard脹r: Eski tip s脹n脹flar ve yeni tip s脹n脹flar. Ancak
korkman脹z脹 gerektirecek kadar fark yoktur bu
iki s脹n脹f tipi aras脹nda. Ayr脹ca hangi s脹n脹f tipini kullan脹rsan脹z
kullan脹n sorun yaamazs脹n脹z. Ama tabii
ki kendimizi yeni tipe al脹t脹rmakta fayda var, 巽端nk端 muhtemelen
Python'un sonraki s端r端mlerinden
birinde (b端y端k ihtimalle Python 3.0'da) eski tip s脹n脹flar
kullan脹mdan kald脹r脹lacakt脹r.
40. Eski tip s脹n脹flar ile yeni tip s脹n脹flar aras脹ndaki en b端y端k fark udur:
Eski tip s脹n脹flar 旦yle tan脹mlan脹r:
class Deneme:
Yeni tip s脹n脹flar ise 旦yle tan脹mlan脹r:
class Deneme(object)
G旦rd端端n端z gibi, eski tip s脹n脹flarda baka bir s脹n脹f脹 miras alma zorunluluu
yoktur. O y端zden s脹n脹flar脹 istersek parantezsiz olarak tan脹mlayabiliyoruz.
Yeni tip s脹n脹flarda ise her s脹n脹f mutlaka baka bir s脹n脹f脹 miras almal脹d脹r. Eer
kodlar脹n脹z i巽inde ger巽ekten miras alman脹z gereken baka bir s脹n脹f yoksa,
旦ntan脹ml脹 olarak "object" adl脹 s脹n脹f脹 miras alman脹z gerekiyor. Dolay脹s脹yla
politikam脹z u olacak:
"Ya bir s脹n脹f脹 miras al, ya da miras alman gereken herhangi bir s脹n脹f
yoksa, "object" adl脹 s脹n脹f脹 miras al..."
41. KAYNAKLA
R
[1] Python D旦k端mantasyonu (http://www.python.org/doc/current/
[2] Python K脹lavuzu (
http://www.geocities.com/dinceraydin/python/tut/tut.html)
[3] Dive Into Python (http://www.diveintopyhton.org)
[4] Python Style Guide (http://www.python.org/doc/essays/styleguide.html)
[5] Python, Mustafa Baer, 2002
Editor's Notes
#7: Eg identifier is a token that can have lexemes such a s sum and total Examples of tokens and lexemes on p 106 of statement (on previous page) index = 2 * count + 17;
#12: Explain meta symbols used ::= - consists of is the same as | - or Explain the process of derivation starting with the goal symbol of the language The multiple sentential forms are shown on next slide Further examaple on p 109 of text Grammar for a small language
#13: in this derivation the leftmost non terminal is replaced - this is called a leftmost derivation the sentential form consisting of only terminals (lexemes) is the generated sentence. Most languages are infinite so cannot generate all sentences Conversely could start with a sentence the apple eats the man and work backward through the derivation to arrive at <sentence> and so have shown that the sentence is legal in the language. Louden p,67 Articles at the beginning of sentence should have capital Such positional properties not easy in context-free grammars
#17: Grammars naturally describe the hierarchical syntactic structure of sentences The parse tree is labeled by nonterminals at interior nodes and terminals at leasves All terminals and nonterminals in a derivation are included Every Subtree of a parse tree describes one instance of an abstraction in a grammar statements Not all terminals and nonterminals may be necessary to determine the structure Abstract syntax trees abstract the essential structure of the parse tree