Mỗi ngôn ngữ lập trình có từ khóa (keyword) và định danh (identifier) khác nhau và Python cũng không ngoại lệ. Trong bài này chúng ta sẽ tìm hiểu về từ khóa Python là từ dành riêng cho Python và định danh là tên cho các biến, hàm trong Python.

Keyword của Python

Keyword của Python như đã nói là những từ chỉ dành riêng cho Python. Bạn không thể sử dụng những keyword này để đặt tên cho biến, hay sử dụng chúng như các hằng, tên định danh.

Trong Python, ngoại trừ True, False và None được viết hoa ra thì các keyword khác đều được viết dưới dạng chữ thường, đây là điều bắt buộc.

Dưới đây là danh sách các từ khóa trong ngôn ngữ lập trình Python: (Danh sách này tính đển Python 3.0, các phiên bản mới hơn có thể có thêm keyword bổ sung)

  • False
  • class
  • finally
  • is
  • return
  • None
  • continue
  • for
  • lambda
  • try
  • True
  • def
  • from
  • nonlocal
  • while
  • and
  • del
  • global
  • not
  • with
  • as
  • elif
  • if
  • or
  • yield
  • assert
  • else
  • import
  • pass
  • break
  • except
  • in
  • raise

Định danh trong Python

Định danh là tên được đặt cho các thực thể như class, function, biến,… trong Python. Nó giúp phân biệt thực thể này với thực thể khác.

Quy tắc viết định danh và vài tips cho định danh trong Python:

  • Định danh có thể là sự kết hợp giữa các chữ cái viết thường (từ a đến z) hoặc viết hoa (A đến Z) hoặc các số (từ 0 đến 9) hoăc dấu gạch dưới (_). Định danh hợp lệ sẽ giống như thế này: bien_1, tinh_tong_0_9, firstClass.
  • Định danh không thể bắt đầu bằng một chữ số, ví dụ 1bien là không hợp lệ, nhưng bien1 thì đúng.
  • Định danh phải khác các keyword. Bạn thử nhập and = 1 rồi chạy sẽ xuất hiện thông báo lỗi “SyntaxError: invalid syntax”.
  • Python không hỗ trợ các ký tự đặc biệt như !, @, #, $, %,… trong định danh. Nếu cố tình gán các ký tự này trong định danh bạn cũng sẽ nhận được thông báo lỗi “SyntaxError: invalid syntax” hoặc “NameError:…”
  • Định danh có thể dài bao nhiêu tùy ý.
  • Tên lớp thường bắt đầu với một chữ cái hoa. Tất cả các định danh khác bắt đầu với chữ cái thường.
  • Định danh bắt đầu với một dấu dạch dưới _ thì là định danh private.
  • Định danh bắt đầu với 2 dấu gạch dưới __ thì mức độ private cao hơn.
  • Nếu định danh bắt đầu và kết thúc bằng 2 dấu gạch dưới (__init__ chẳng hạn) thì định danh đó là tên đặc biệt được ngôn ngữ định nghĩa.
  • Nên đặt tên định danh có nghĩa. Dù c = 10 vẫn đúng, nhưng viết count = 10 sẽ rõ nghĩa hơn và dễ hiểu nó là gì hơn dù bạn đã xem code một đoạn dài sau đó.
  • Python là ngôn ngữ lập trình phân biệt chữ hoa, chữ thường, nghĩa là bien và Bien là không giống nhau.
  • Khi đặt định danh nhiều từ bạn có thể dùng dấu gạch dưới giữa các từ, day_la_mot_bien_dai, kiểu vậy.
  • Bạn có thể viết theo phong cách HoaRoiThuong như thế này để phân biệt các từ trong trường hợp biến dài.

Vậy là bạn đã nắm được những quy tắc cơ bản về keyword và định danh trong Python rồi. Trong bài tiếp theo chúng ta sẽ biết về cách viết lệnh, thụt lề và bình luận trong Python.

324 BÌNH LUẬN

  1. I do not know if it’s just me or if everyone else experiencing
    issues with your website. It appears as if some of the text
    on your content are running off the screen. Can somebody else please comment and let me know if this is happening
    to them as well? This may be a problem with my browser because I’ve had this happen before.
    Many thanks

  2. I simply could not leave your web site prior to suggesting that I
    actually loved the standard info an individual provide to your guests?
    Is going to be again frequently in order to inspect new posts

  3. Great goods from you, man. I’ve be aware your stuff prior to and you’re
    just extremely fantastic. I really like what you’ve acquired
    here, certainly like what you’re saying and the best way by
    which you say it. You make it enjoyable and you continue to take care of to keep it smart.
    I can’t wait to learn far more from you. That is actually a wonderful
    website.

  4. I’m more than happy to discover this web site.

    I need to to thank you for your time for this particularly fantastic read!!
    I definitely really liked every bit of it and I have you book marked to check out new stuff in your website.

  5. Incredible! This blog looks just like my old one! It’s on a totally different topic but it has pretty
    much the same layout and design. Superb choice of colors!

  6. Undeniably believe that which you said. Your
    favorite reason appeared to be on the net the simplest
    thing to be aware of. I say to you, I definitely get annoyed while people think
    about worries that they plainly don’t know about.

    You managed to hit the nail upon the top as well as defined out the whole thing without having side-effects , people could take a signal.
    Will probably be back to get more. Thanks

  7. Along with almost everything which seems to be developing
    throughout this area, a significant percrntage of viewpoints happen to be
    relatively radical. However, I amm sorry, but
    I do not subscribe tto your whole idea, all be it refreshing none the less.
    It looks to us that your remarks are not entirely justified and in reality you are your
    self not wholly concident of your assertion. In any case I did appreciate examining
    it.

  8. Unquestionably believe that which you said. Your
    favorite reason appeared to be on the web the easiest thing
    to be aware of. I say to you, I certainly get irked while people
    think about worries that they plainly don’t know about.
    You managed to hit the nail upon the top and also defined out the whole thing
    without having side-effects , people can take a
    signal. Will likely be back to get more. Thanks

  9. I was curious if you ever thought of changing
    the structure of your blog? Its very well written; I love what youve
    got to say. But maybe you could a little more in the way of content so people could connect with it
    better. Youve got an awful lot of text for only having one or 2 images.
    Maybe you could space it out better?

  10. Oh my goodness! Incredible article dude! Thanks, However I am encountering difficulties with your RSS.

    I don’t understand why I cannot join it. Is there anybody getting identical RSS problems?
    Anybody who knows the answer will you kindly respond?

    Thanks!!

  11. Hi there just wanted to give you a quick
    heads up and let you know a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different internet browsers and both show the same
    results.

  12. Link exchange is nothing else except it is only
    placing the other person’s web site link on your page
    at proper place and other person will also do same in support of you.

  13. Wow, wonderful blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is great, let alone the content!. Thanks For Your article about sex.

  14. Great beat ! I wish to apprentice while you amend your web site,
    how can i subscribe for a blog site? The account helped me a acceptable deal.
    I had been tiny bit acquainted of this your broadcast provided
    bright clear idea

  15. Thanks for another great post. Where else may anybody get that type of info in such an ideal way of writing? I have a presentation next week, and I am at the search for such information.

  16. This very blog is no doubt entertaining and besides diverting. I have picked helluva helpful tips out of this source. I ad love to go back every once in a while. Thanks a bunch!

  17. Very nice article and straight to the point. I am not sure if this is really the best place to ask but do you folks have any thoughts on where to employ some professional writers? Thanks in advance

  18. Thanks for another wonderful post. Where else could anybody get that type of information in such an ideal way of writing? I ave a presentation next week, and I am on the look for such information.

  19. What as up to every body, it as my first pay a visit of this web site; this website consists of amazing and genuinely good data designed for visitors.

  20. Nice blog here! Also your site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my site loaded up as quickly as yours lol

  21. Wow, fantastic weblog format! How lengthy have you been running a blog for? you made blogging look easy. The overall look of your website is fantastic, let alone the content!

  22. Thanks , I ave recently been looking for info about this subject for ages and yours is the best I have discovered till now. But, what about the bottom line? Are you sure about the source?

  23. Whats up. Very nice site!! Man.. Beautiful.. Wonderful.. I all bookmark your blog and take the feeds alsoI am satisfied to locate numerous useful info here within the post. Thank you for sharing

  24. What as Happening i am new to this, I stumbled upon this I have found It absolutely helpful and it has helped me out loads. I hope to contribute & help other users like its helped me. Good job.

  25. I know this if off topic but I’m looking into starting
    my own blog and was curious what all is needed to
    get setup? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet smart so I’m not 100% positive.
    Any suggestions or advice would be greatly appreciated.

    Kudos

  26. Sweet blog! I found it while browsing on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I ave been trying for a while but I never seem to get there! Many thanks

  27. An outstanding share! I have just forwarded this onto a friend who has been doing a
    little homework on this. And he actually ordered me lunch simply
    because I found it for him… lol. So allow me to reword this….
    Thank YOU for the meal!! But yeah, thanx for spending time to talk
    about this subject here on your web site.

  28. Wow! This could be one particular of the most beneficial blogs We ave ever arrive across on this subject. Actually Fantastic. I am also a specialist in this topic so I can understand your hard work.

  29. Whats Happening i am new to this, I stumbled upon this I ave discovered It positively useful and it has aided me out loads. I hope to contribute & help different users like its aided me. Good job.

  30. What’s up to all, how is the whole thing, I think every one is
    getting more from this web site, and your views are fastidious in support of
    new users.

  31. I think other web site proprietors should take this website as an model, very clean and magnificent user friendly style and design, as well as the content. You are an expert in this topic!

  32. This is really interesting, You are a very skilled blogger. I ave joined your feed and look forward to seeking more of your excellent post. Also, I have shared your web site in my social networks!

  33. Its like you read my mind! You appear to know a
    lot about this, like you wrote the book in it or something.
    I think that you could do with a few pics to drive the message
    home a bit, but instead of that, this is excellent blog.

    An excellent read. I’ll certainly be back.

  34. After I originally commented I seem to have clicked the -Notify me when new comments are added- checkbox and from
    now on each time a comment is added I receive 4 emails with the same
    comment. Is there a means you can remove me from that service?
    Thanks a lot!

  35. Thank you for another excellent post. Where else could anybody get that kind of information in such a perfect way of writing? I ave a presentation next week, and I am on the look for such info.

  36. Usually My spouse and i don at send ahead web sites, on the contrary I may possibly wish to claim that this particular supply in fact forced us to solve this. Fantastically sunny submit!

  37. Modular Kitchens have changed the idea of kitchen in today as world since it has provided household ladies with a comfortable yet an elegant area where they could devote their quality time and space.

  38. You have mentioned very interesting details ! ps decent internet site. I didn at attend the funeral, but I sent a nice letter saying that I approved of it. by Mark Twain.

  39. Thank you, I ave just been looking for info about this subject for ages and yours is the greatest I have discovered so far. But, what about the conclusion? Are you sure about the source?

  40. You made some really good points there. I checked on the internet for additional information about the issue and found most individuals will go along with your views on this site.

  41. Awesome blog you have here but I was curious if you
    knew of any user discussion forums that cover the same topics discussed here?

    I’d really love to be a part of group where
    I can get suggestions from other knowledgeable people that share the same interest.
    If you have any recommendations, please let me know. Bless you!

  42. Usually I don at learn article on blogs, but I wish to say that this write-up very compelled me to take a look at and do it! Your writing taste has been surprised me. Thanks, very nice post.

  43. That is a really good tip particularly to those new to the blogosphere. Brief but very accurate information Appreciate your sharing this one. A must read article!

  44. Usually I don at read post on blogs, but I would like to say that this write-up very forced me to try and do so! Your writing taste has been amazed me. Thank you, very nice article.

  45. Normally I do not read article on blogs, however I wish to say that this write-up very forced me to check out and do it! Your writing style has been amazed me. Thanks, quite nice article.

  46. You have made some really good points there. I looked on the net for additional information about the issue and found most people will go along with your views on this website.

  47. Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is excellent, let alone the content!. Thanks For Your article about sex.

  48. Spot on with this write-up, I honestly think this web site needs far more attention. I all probably be returning to read more, thanks for the advice!

  49. This is very interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your great post. Also, I ave shared your site in my social networks!

  50. It’а†s in reality a nice and helpful piece of info. I am satisfied that you just shared this useful info with us. Please stay us up to date like this. Thank you for sharing.

  51. Such runescape are excellent! We bring the runescape you will discover moment and so i really like individuals! My associates have got an twosome. I like This runescape!!!

THOÁT KHỎI BÌNH LUẬN

Please enter your comment!
Please enter your name here