Tag: Syntax
Posts of Tag: Syntax
  1. Difference between Syntax and Semantics

    Difference between Syntax and Semantics Here you will learn about difference between Syntax and Semantics with example. The both terms might seem the same things but they are not, they are just interrelated con...Learn More
  2. Which is more preferable to use in Python: lambda functions or nested functions ('def')?

    I mostly use lambda functions but sometimes use nested functions that seem to provide the same behavior. Here are some trivial examples where they functionally do the same thing if either were found within ano...Learn More
  3. In Python, how I do use subprocess instead of os.system?

    I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"): import os sqlpubwiz = r'"...Learn More
  4. How can I concatenate regex literals in JavaScript?

    Is it possible to do something like this? var pattern = /some regex segment/ + /* comment here */ /another segment/; Or do I have to use new RegExp() syntax and concatenate a string? I'd prefer to use the ...Learn More
  5. Why does Java not have block-scoped variable declarations?

    The following method does not work because the inner block declares a variable of the same name as one in the outer block. Apparently variables belong to the method or class in which they are declared, not to t...Learn More
  6. How do I get a decimal value when using the division operator in Python?

    For example, the standard division symbol '/' rounds to zero: >>> 4 / 100 0 However, I want it to return 0.04. What do I use?...Learn More
  7. Mixed syntax for control structures generating syntax errors

    I'm refactoring some PHP code and discovered that certain nested combinations of if () : and if () { generate syntax errors. Not that I would normally mix the two, but I like to do frequent syntax checks a...Learn More
  8. What does ** (double star) and * (star) do for Python parameters?

    In the following method definitions, what does the * and ** do for param2? def foo(param1, *param2): def bar(param1, **param2): ...Learn More
  9. How can I closely achieve ?: from C++/C# in Python?

    In C# I could easily write the following: string stringValue = string.IsNullOrEmpty( otherString ) ? defaultString : otherString; Is there a quick way of doing the same thing in Python or am I stuck with an 'i...Learn More
  10. Using for...else in Python generators

    I'm a big fan of Python's for...else syntax - it's surprising how often it's applicable, and how effectively it can simplify code. However, I've not figured out a nice way to use it in a generator, for example:...Learn More
  11. How can I do a line break (line continuation) in Python?

    I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax? For example, adding a bunch of strings, e = 'a' + 'b' + 'c' + 'd' and have it like this: e = 'a' +...Learn More
  12. Can you add new statements to Python's syntax?

    Can you add new statements (like print, raise, with) to Python's syntax? Say, to allow.. mystatement "Something" Or, new_if True: print "example" Not so much if you should, but rather if it's possible (sh...Learn More